我在我的网站上有会员服务。目前,当有人登录了,他们将被重定向到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
顺便说一句,出于安全原因,确保在将它们插入数据库时转义变量。查看“SQL注入”和“mysql_real_escape_string()”http://php.net/manual/en/function.mysql-real-escape-string.php – 2013-03-24 03:55:44
在顶部添加:<?php ob_start(); ?> – Andres 2013-03-24 04:19:58