2013-02-12 68 views
0

嗨即时尝试将一个if语句,说登录后,如果用户帐户被禁止,然后重定向到logout.php记录用户出,但我也想在这种情况发生后显示会话消息。可以这样做,即时尝试执行以下操作,但只能将用户重定向到注销并登出,而不显示会话消息。如果条件为真重定向到注销并显示会话消息?

请能有人告诉我在哪里,我去错了感谢:

<? if (logged_in()) { ?> 
    <? 
    $account_banned = account_banned(); 
    while ($banned = mysql_fetch_array($account_banned)) 


    if ($banned['account_banned'] == '1') { 
     $_SESSION['banned']="<div class=\"infobox-noprofile\"><strong>Account Banned</strong> - We could not log you in because your account has been banned. If you need to talk to us about this please email <a href=\"mailto:[email protected]\">[email protected]</a></div><div class=\"infobox-close12\"></div>"; 

      redirect_to("logout.php"); 


    ?> 

    <? } }?> 
在logout.php

<? 
session_start(); 
if(isset($_SESSION['banned'])) 
    echo $_SESSION['banned']; 
    unset($_SESSION['banned']); 

?> 
+0

'redirect_to'做了什么? – 2013-02-12 19:05:37

+0

你缺少session_start();在第一页 – Nimrod007 2013-02-12 19:08:00

回答

1

你在第一个文件丢失session_start();。注销处理在哪里?此人仍然登录(至少如果他是摆在首位)

0

请不要保存那种会话变量里面的值,而不是这样做:

第一个文件:

<?php if (logged_in()) { 
     $account_banned = account_banned(); 
     while ($banned = mysql_fetch_array($account_banned)) 


     if ($banned['account_banned'] == '1') { 
      $_SESSION['banned']= true; 

       redirect_to("logout.php"); 
     } 
     } 
?> 

logout.php

<?php 

    session_start(); 
    if(isset($_SESSION['banned'])):?> 
    <div class="infobox-noprofile"><strong>Account Banned</strong> - We could not log you in because your account has been banned. If you need to talk to us about this please email <a href="mailto:[email protected]">[email protected]</a></div><div class="infobox-close12"></div> 

<?php endif; 
unset($_SESSION['banned']); 
?>