如果条件为真,则重定向到注销并显示会话消息?

时间:2013-02-12 19:03:42

标签: php mysql

嗨我试图在登录后发出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:support@playtimeboys.com\">Support@PlaytimeBoys.com.</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']);

?>

2 个答案:

答案 0 :(得分:1)

您在第一个文件中缺少session_start();。注销处理在哪里?该人仍然登录(至少如果他是第一位的话)

答案 1 :(得分: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:support@playtimeboys.com">Support@PlaytimeBoys.com.</a></div><div class="infobox-close12"></div>

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