我遇到了一个问题。我的代码(代码在Controller中):
public function login(Request $request){
$name = $request->name;
$pwmd5 = md5($request->pw);
$result= user::select(DB::raw("CASE WHEN password ='$pwmd5' THEN 1 ELSE 0 END AS passwrod_matches,id,name"))
->where('name',$name)
->first();
if ($result == null) {
return returnFormat('account wrong', false);
} elseif ($result['password_matches'] == '0') {
return returnFormat('pw wrong', false);
};
$result['password_status'] = '1';
static::saveUser($result);
return returnFormat($result);
}
static public function saveUser(&$user){
if(!is_array($user)){
$user->toArray();
}
$user['sid'] = Session::getId();
session(['user'=>$user]);
}
public function checkUser(Request $request){
$user = session('user');
return $user;
}
public function logout(Request $request){
session()->flush();
return returnFormat(true);
}
我做的是login() - > checkuser() - >登出(); 但是当我用另一个帐户登录()时,我发现会话ID完全一样..为什么?
答案 0 :(得分:3)
销毁会话的三种方法:
1)
Session::flush(); // removes all session data
2)
Session::forget('yourKeyGoesHere') // Removes a specific variable
3)
Auth::logout() // logs out the user