我的网站上有成员(member)服务。目前,当有人注销时,他们会被重定向到 logout.php,上面有这段代码:
<?php
//check if the login session does no exist
if(strcmp($_SESSION['uid'],”) == 0){
//if it doesn't display an error message
echo "<center>You need to be logged in to log out!</center>";
}else{
//if it does continue checking
//update to set this users online field to the current time
mysql_query("UPDATE `users` SET `online` = '".date('U')."' WHERE `id` = '".$_SESSION['uid']."'");
//destroy all sessions canceling the login session
session_destroy();
//display success message
echo "<center>You have successfully logged out!<br><a href = '/review-pratt/index.php' class='icon-button star'>Return Home</button></center>";
}
?>
而不是让用户被带到“logout.php”并查看一个无聊的页面,说他们注销了。我希望将它们重定向到 index.php。这部分很简单,我知道。
我希望在顶部出现一个通知栏,通知他们已成功注销。我以前尝试过这样做,但从来没有任何效果。如有任何帮助或建议,我们将不胜感激!
更新
我已将 logout.php 代码更改为:
<?php
//check if the login session does no exist
if(strcmp($_SESSION['uid'],”) == 0){
//if it doesn't display an error message
echo "<center>You need to be logged in to log out!</center>";
}else{
//if it does continue checking
//update to set this users online field to the current time
mysql_query("UPDATE `users` SET `online` = '".date('U')."' WHERE `id` = '".$_SESSION['uid']."'");
//destroy all sessions canceling the login session
session_destroy();
//Redirect with success message
header('Location: /index.php?msg=' . urlencode("You have been successfully logged out!"));
}
?>
并将以下代码添加到我的 index.php 中:
<?php
if ($_GET['msg'])
{
echo '<div class="success_message">' . base64_decode(urldecode($_GET['msg'])) . '</div>';
}
?>
当我注销时,我收到此错误:
Warning: Cannot modify header information - headers already sent by (output started at /home/content/38/10473938/html/review-pratt/business_profiles/logout.php:19) in /home/content/38/10473938/html/review-pratt/business_profiles/logout.php on line 35
最佳答案
你可以这样做:
header('location: index.php?status=loggedout');
然后在你的 index.php 文件中查看状态是否不为空,并显示一个状态如下的 div:
<?php
if(!empty($_GET['status'])){
echo '<div>You have been logged out!</div>';
}
?>
同样在 if 语句中你也可以清除用户 session ..
关于php - 注销时重定向并显示 "You have successfully logged out!",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15594807/