所以我刚刚把我的php上传到了godaddy,除了正在工作的重定向现在已经停止了。代码在实时服务器上的工作方式和离线之间应该没有区别,所以我不明白发生了什么变化。
以下是不起作用的代码示例
带有注销超链接的标题链接,据我所知,如果
<div id="header">
<div>
<a href="index.php">Home</a>
<div id="loginreglink">
<a href="Logout.php">Log Out</a>
</div>
</div>
</div>
实际注销页面(Logout.php)
<?php
require_once ('Connection.php');
header('Refresh: 0;');
if (!isset($_COOKIE['Username'])){
require ('LoginFunctions.inc.php');
redirect_user();
} else {
setcookie('Username', '', time()-60*60*24*90, '/', '', 0, 0);
require ('RedirectPage.php');
redirect_user();
}
?>
RedirectPage.php(访问注销页面后应立即链接到的下一个页面)
<?php
require ('index.php');
redirect_user();
?>
然后会立即链接回索引,但用户应该注销。这并没有发生。
发生的情况是,页面重定向到索引(应该是这样),大概使用以下顺序,这让我认为重定向是有效的,但用户没有注销。cookie未被删除。我真的不明白为什么它不是,因为它确实通过本地主机上的netbeans工作。
这很容易。打开饼干。
if (!isset($_COOKIE['Username'])){
require ('LoginFunctions.inc.php');
redirect_user();
} else {
setcookie('Username', '', time()-60*60*24*90, '/', '', 0, 0);
require ('RedirectPage.php');
//add this
unset($_COOKIE['Username'];
//or use setcookie and make the time to expire in the past and just put an empty value like
$cookie_name = "Username";
$cookie_value = "";
$time = -3600;
setcookie($cookie_name, $cookie_value, $time, "/");
redirect_user();
}