gpt4 book ai didi

php - 注销 PHP 脚本

转载 作者:可可西里 更新时间:2023-11-01 13:37:00 25 4
gpt4 key购买 nike

这是我的脚本:

<?php
// If the user is logged in, delete the session vars to log them out
session_start();
if (isset($_SESSION['user_id'])) {
// Delete the session vars by clearing the $_SESSION array
$_SESSION = array();

// Delete the session cookie by setting its expiration to an hour ago (3600)
if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time() - 3600); }

// Destroy the session
session_destroy();
}

// Delete the user ID and username cookies by setting their expirations to an hour ago (3600)
setcookie('user_id', '', time() - 3600);
setcookie('username', '', time() - 3600);

// Redirect to the home page
$home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php';
header('Location: ' . $home_url);
?>

我在网站上登录后无法退出。我真的需要 cookie 登录还是可以将其删除?

最佳答案

尝试更简单的方法,销毁所有 session cookie

session_start();
session_destroy();
$home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php';
header('Location: ' . $home_url);

关于php - 注销 PHP 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21320524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com