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: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']);

?>
4

2 回答 2

1

session_start();在第一个文件中丢失了。注销处理在哪里?该人保持登录状态(至少如果他首先是)

于 2013-02-12T19:06:14.893 回答
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");  
         } 
       }
?>

注销.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']);
?>
于 2013-02-12T19:12:09.047 回答