我在我的網站上有會員服務。目前,當有人登錄了,他們將被重定向到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