2013-02-12 45 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']); 
?> 
相關問題