php簡單的登錄登出
今天用PHP做了一個登錄登出的功能
登錄代碼
if($_POST['password']=='xxxxx'){
if (!session_id()) session_start();
$_SESSION['password'] = 'xxxxxx';
$this->getMessage("登錄成功!",'/');
}else{
$this->getMessage("密碼錯誤!",'/');
}
檢查代碼
if (!session_id()) session_start();
$userName = '';
if(isset($_SESSION['password'])&&$_SESSION['password']=='xxxxx'){
$userName= array('id'=>'1','name'=>'admin');
}
if(!empty($userName)){
$GLOBALS['user'] = $userName;
}
登出代碼
if (!session_id()) session_start();
if(isset($_SESSION['password'])){
unset($_SESSION['password']);
}
$this->getMessage("登出成功!",'/xxxx');
思路就是這樣根據$GLOBALS['user']的值是否為空來判斷用戶是否登錄。
請關注我們微信公眾號:mw748219