标题();注销后不工作] session_destroy()]

问题描述 投票:2回答:3

我的logout.php有这个代码:

<?php

session_start();

$_SESSION = array();

if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
    $params["path"], $params["domain"],
    $params["secure"], $params["httponly"]
);
}

session_destroy();
    header( "Location: index.php" ); //to redirect back after logging out
?>

问题是标题不起作用。我不知道它是否与上面的代码有任何关系..但我不这么认为,因为它适用于localhost - wamp服务器。那是因为我正在使用的服务器吗?或者代码中有问题吗?

谢谢!

php redirect header logout
3个回答
0
投票

这是因为Header Redirect需要数据缓冲打开,它可能在服务器上被禁用,尝试添加ob_start();之后你session_start();


0
投票

试试吧:

header( "Location: http://hostname.com/full_path/index.php" );

或者如果在使用标头时遇到错误,请尝试以下代码:

echo "<script>window.location.href='http://hostname.com/full_path/index.php'</script>";

0
投票

尝试这可能它的工作原理:

echo '<META HTTP-EQUIV="Refresh" Content="0; URL=index.php">';    
exit; 
© www.soinside.com 2019 - 2024. All rights reserved.