这是我的logout.php中的代码。
session_start();
session_unset();
session_destroy();
header("Location: ../index.php");
当我在我的localhost中运行它时,此代码正常工作,但是当我将其上传到我的服务器时,它无法正常工作,并且无法从我的网站注销。 请有人帮助我通过'谢谢你。
答案 0 :(得分:0)
有多种情况可能导致logout.php不起作用。最常见的一种是,您的权限不正确,并且无法在服务器上创建会话文件。
要检查是否是这种情况,我建议您启用错误报告。您可以通过将以下行放在PHP文件的顶部来完成此操作:
// Put this code in your logout.php temporarily
error_reporting(E_ALL);
ini_set('display_errors', 'On');
然后,确保您的会话尚未启动。
// Replace session_start(); in all files with this
if (!isset($_SESSION)) {
session_start();
}
我希望上面的代码更改会向您显示您的错误。
答案 1 :(得分:-2)
确保您的会话在销毁之前已初始化。
session_start() ;
var_dump($_SESSION); // Check session is set/not
session_destroy() ;
header("Location: ../index.php");
如果您有任何会话值打印,那么我们肯定可以销毁它。