2 回答
TA贡献1856条经验 获得超11个赞
你需要:
destroy_session();
或者您需要删除会话变量:
unset($_SESSION);
您可以重定向到索引页面:
header('Location: index.php);
exit();
如果会话在数据库上工作,则销毁会话对象。
$pdo = new PDO('mysql:host=localhost;dbname=produkty', 'root', 'root');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare('SELECT COUNT(*) as cnt FROM users WHERE user_id = :s1');
$stmt->execute( array( ':s1' => $userid ) );
$cnt = $stmt->fetchAll()[0]['cnt'];
if($cnt == 0){
session_destroy();
// destroy session here
}
TA贡献1788条经验 获得超4个赞
//call this function at top of every page after login
function checkexistuser(){
$user_id = $_SESSION['user_id'];
$query = "SELECT * FROM users WHERE user_id = '".$user_id."' ";
$result = $this->db->select($query);
if($result->num_rows() == 0){
//destroy_session , redirect, show message whatever you want.
}
}
- 2 回答
- 0 关注
- 211 浏览
添加回答
举报