本文整理匯總了PHP中session函數的典型用法代碼示例。如果您正苦於以下問題:PHP session函數的具體用法?PHP session怎麽用?PHP session使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了session函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: slots
public function slots()
{
$user = Auth::user();
$location = $user->location;
$slot = Slot::where('location', '=', $location)->first();
$input = Input::get('wager');
$owner = User::where('name', '=', $slot->owner)->first();
$num1 = rand(1, 10);
$num2 = rand(5, 7);
$num3 = rand(5, 7);
if ($user->name != $owner->name) {
if ($num1 & $num2 & $num3 == 6) {
$money = rand(250, 300);
$payment = $money += $input * 1.75;
$user->money += $payment;
$user->save();
session()->flash('flash_message', 'You rolled three sixes!!');
return redirect('/home');
} else {
$user->money -= $input;
$user->save();
$owner->money += $input;
$owner->save();
session()->flash('flash_message_important', 'You failed to roll three sixes!!');
return redirect(action('SlotsController@show', [$slot->location]));
}
} else {
session()->flash('flash_message_important', 'You own this slot!!');
return redirect(action('SlotsController@show', [$slot->location]));
}
}
示例2: exits
/**
*
*前台退出
*
*/
public function exits()
{
session('user_uid', null);
session('user_name', null);
session('user_verify', null);
$this->success("用戶退出成功", '__ROOT__/Logo/login.html');
}
示例3: getValidateToken
/**
*
* @return \Illuminate\Http\Response
*/
public function getValidateToken()
{
if (session('2fa:user:id')) {
return view('2fa/validate');
}
return redirect('login');
}
示例4: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (session('statut') === 'admin') {
return $next($request);
}
return new RedirectResponse(url('/kadmin/login'));
}
示例5: verify
public function verify($username, $password)
{
$credentials = ['username' => $username, 'password' => $password];
$person = new Person();
$resp = $person->getUsername($credentials['username']);
if (!empty($resp)) {
if (\Hash::check($credentials['password'], $resp['password'])) {
$auth = true;
} else {
//check for old hashing
if (md5($credentials['password']) == $resp['password']) {
//convert old pass to new hashing
$resp['password'] = bcrypt($credentials['password']);
$id = my_encode($resp['id']);
$person->update($id, $resp);
$auth = true;
} else {
$auth = false;
}
}
} else {
//invalid user
$auth = false;
}
if ($auth) {
$result = $person->respondWithItem($resp, new UserTransformer());
session()->put('user', $result);
return my_decode($resp['id']);
}
return false;
}
示例6: index
public function index()
{
if (!session('openid_' . $this->token)) {
$this->info = M('wxuser')->where(array('token' => $this->token))->find();
vendor("Oauth2.OAuth2", LIB_PATH . '../Extend/Vendor');
vendor("Oauth2.Provider.Wechat", LIB_PATH . '../Extend/Vendor');
$wechat = new Wechat();
$wechat->config(array('id' => $this->info['appid'], 'secret' => $this->info['appsecret']));
$redirect_uri = C('site_url') . '/index.php/Wap/Coupons/index?token=' . $this->token . '&coupon_id=' . $this->coupon_id;
if (!$_GET['code']) {
// By sending no options it'll come back here
$url = $wechat->authorize(array('redirect_uri' => $redirect_uri));
redirect($url);
} else {
try {
// Have a go at creating an access token from the code
$token = $wechat->access($_GET['code'], array('redirect_uri' => $redirect_uri));
// Use this object to try and get some user details (username, full name, etc)
$user = $wechat->get_user_info($token);
$this->openid = $user->openid;
session('openid_' . $this->token, $user->openid);
} catch (OAuth2_Exception $e) {
print_r($e);
die;
}
}
} else {
$this->openid = session('openid_' . $this->token);
}
$url = C('site_url') . "/index.php?g=Wap&m=Coupon&a=index&type=1&token=" . $this->token . '&id=' . $this->coupon_id . '&wecha_id=' . $this->openid;
header('Location:' . $url);
}
示例7: xiugai
public function xiugai()
{
$mana = M('manager');
$name = session('username');
$ps = $mana->where("username='{$name}'")->getField('password');
$error = '';
if (IS_POST) {
if (intval(I('post.state')) === 1) {
if (md5(I('post.opassword')) === $ps) {
$initial = md5('123456');
$mana->where("username='{$name}'")->setField('password', $initial);
$this->success('初始化成功', U('index/index'), 2);
} else {
$error = '初始化失敗,原密碼輸入錯誤';
$this->assign('error', $error);
$this->display('Admin/index');
}
} else {
if (md5(I('post.opassword')) === $ps) {
$nps = md5(I('post.npassword'));
$mana->where("username='{$name}'")->setField('password', $nps);
$this->success('修改密碼成功', U('index/index'), 2);
} else {
$error = '原密碼輸入錯誤,修改密碼失敗';
$this->assign('error', $error);
$this->display('Admin/index');
}
}
}
}
示例8: autoLogin
public function autoLogin()
{
if (cookie('token')) {
$token = cookie('token');
$userId = $token['userId'];
if (!is_numeric($userId)) {
return 0;
}
$User = D('User');
$user = $User->find($userId);
if ($user['userId'] != $userId) {
return 0;
}
if ($token['verify'] != sha1(md5($user['password']))) {
return 0;
}
session('userId', $user['userId']);
session('userName', $user['userName']);
session('icon', $user['icon']);
session('email', $user['email']);
session('signature', $user['signature']);
session('score', $user['score']);
session('registerTime', format_date($user['registerTime']));
session('lastLoginTime', format_date($user['lastLoginTime']));
//更新上次登錄時間
$User->where("userId={$userId}")->setField('lastLoginTime', date('Y-m-d H:i:s', time()));
cookie('token', $token, 864000);
return 1;
} else {
return 0;
}
}
開發者ID:AlexanderFeng,項目名稱:a-simple-question-and-answer-website,代碼行數:32,代碼來源:AutoLoginController.class.php
示例9: destroy
public function destroy($id)
{
$wallet = Wallet::findOrFail($id);
$wallet->delete();
session()->flash('flash_message', 'Data Deleted!');
return redirect('wallets');
}
示例10: _initialize
/**
* 初始化方法
* @author jry <598821125@qq.com>
*/
protected function _initialize()
{
//隻有ID為1的超級管理員才有權限係統更新
if (session('user_auth.uid') !== '1') {
$this->success('');
}
}
示例11: index
public function index()
{
if (session('?userName')) {
$this->userName = session('userName');
//前台顯示登錄用戶名
$this->logout = session('logout');
$user['userId'] = session('userId');
//鏈接2張表
/*
教你如何寫thinkphp多表查詢語句 (2011-04-07 13:18:44)轉載▼
1、table()函數
thinkphp中提供了一個table()函數,具體用法參考以下語句:
$list=$Demo->table('think_blog blog,think_type type')->where('blog.typeid=type.id')->field('blog.id as id,blog.title,blog.content,type.typename as type')->order('blog.id desc' )->limit(5)->select();
echo $Demo->getLastSql(); //打印一下SQL語句,查看一下
2、join()函數
看一下代碼:
$Demo = M('artist');
$Demo->join('RIGHT JOIN think_work ON think_artist.id = think_work.artist_id' );
//可以使用INNER JOIN 或者 LEFT JOIN 這裏一定要注意表名的前綴!
echo $Demo->getLastSql(); //打印一下SQL語句,查看一下
*/
$mybooks = D("booklib")->join(' INNER JOIN books ON books.id = booklib.bookId')->where($user)->select();
$this->assign('mybooks', $mybooks);
$this->display();
} else {
header("Content-Type:text/html; charset=utf-8");
redirect('login', 0, '請先登錄!');
}
}
示例12: nocemid
public function nocemid()
{
$nocemid = 'not_eligible';
session(['key' => $nocemid]);
return redirect('/client_enrolment')->with('info', 'Clent is not Eligible, enter client details to update register');
//return view('layouts.results',compact('users'));
}
示例13: callback
/**
* 登陸後回調地址
*/
public function callback()
{
$code = I('get.code');
$type = I('get.type');
$sns = \ThinkOauth::getInstance($type);
//騰訊微博需傳遞的額外參數
$extend = null;
if ($type == 'tencent') {
$extend = array('openid' => I('get.openid'), 'openkey' => I('get.openkey'));
}
$token = $sns->getAccessToken($code, $extend);
//獲取第三方Token
$user_sns_info = \ThinkOauthInfo::$type($token);
//獲取第三方傳遞回來的用戶信息
$user_sync_info = D('Addons://SyncLogin/SyncLogin')->getUserByOpenidAndType($token['openid'], $type);
//根據openid等參數查找同步登錄表中的用戶信息
$user_sys_info = D('User')->find($user_sync_info['uid']);
//根據UID查找係統用戶中是否有此用戶
if ($user_sync_info['uid'] && $user_sys_info['id'] && $user_sync_info['uid'] == $user_sys_info['id']) {
//曾經綁定過
D('Addons://SyncLogin/SyncLogin')->updateTokenByTokenAndType($token, $type);
D('User')->autoLogin($user_sys_info);
redirect('http://' . $_SERVER['HTTP_HOST'] . __ROOT__);
} else {
//沒綁定過,去注冊頁麵
session('token', $token);
session('user_sns_info', $user_sns_info);
$this->assign('user_sns_info', $user_sns_info);
$this->assign('meta_title', "登陸");
$this->display(T('Addons://SyncLogin@./default/reg'));
}
}
示例14: loaded
public function loaded()
{
$camplog = new CampaignLog(['user' => ['session' => session('_token')], 'device' => ['mac' => "test mac xD"], 'interaction' => ['welcome' => new MongoDate()]]);
$camplog->save();
return \Request::all();
// return true;
}
示例15: submitNickname
/**
* 修改昵稱提交
* @author huajie <banhuajie@163.com>
*/
public function submitNickname()
{
//獲取參數
$nickname = I('post.nickname');
$password = I('post.password');
empty($nickname) && $this->error('請輸入昵稱');
empty($password) && $this->error('請輸入密碼');
//密碼驗證
$User = new UserApi();
$uid = $User->login(UID, $password, 4);
$uid == -2 && $this->error('密碼不正確');
$Member = D('Member');
$data = $Member->create(array('nickname' => $nickname));
if (!$data) {
$this->error($Member->getError());
}
$res = $Member->where(array('uid' => $uid))->save($data);
if ($res) {
$user = session('user_auth');
$user['username'] = $data['nickname'];
session('user_auth', $user);
session('user_auth_sign', data_auth_sign($user));
$this->success('修改昵稱成功!');
} else {
$this->error('修改昵稱失敗!');
}
}