duanjia7912 2011-04-24 13:15
浏览 22
已采纳

登录时禁止系统的问题

I've created the following banning system when a user logins on my site. It checks if the user is banned, and then follows a process to gather information, and finally brings up a notice and doesn't let the user login. However, this does not happen and I can login fine. Any help would be appriciated.

    $un9 = "gdscei";
    $checkban = mysql_query("SELECT * FROM bans WHERE usr = '" .$un9. "'") or die(mysql_error());
        if(mysql_num_rows($checkban) != 0){
            $query7 = "SELECT * FROM bans WHERE usr = '".$un9."'";
    $result7 = mysql_query($query7) or die(mysql_error());
    while ($row7 = mysql_fetch_assoc($result7)) {
        $reas = $row7['reas'];
        $timeb = $row7['time'];
        $tban = $row7['tban'];
            $tip = $row7['ipd'];
    };
    if($timeb == "perm"){
        $bant = "Permanent";
    }else{
        $bant = $timeb;
    };
    $checkusrdel = mysql_query("SELECT * FROM users WHERE username = '".$un9."'") or die(mysql_error());
    if(mysql_num_rows($checkusrdel) != 0){
    $acdel = "n";
    }else{
    $acdel = "y";
    };
    if(empty($tip) && acdel == "n"){
    $bank = "account ban";
    }else if($acdel == "y" && empty($tip)){
    $bank = "account deleted";
    }else if($acdel == "y" && $tip){
    $bank = "account deleted + IP ban";
    }else{
    $bank = "account ban + IP ban";
    };
    $notice = '<script type="text/javascript">alert("You have been banned, as followed: "'.$bank.'". Your ban lasts until "'.$bant.'"."); window.open("login.php","_self");</script>';
    };
  • 写回答

2条回答 默认 最新

  • dongpo1216 2011-04-24 13:32
    关注

    The solution is simpler than you may have imagined:

    $notice = '<script type="text/javascript">alert("You have been banned, as followed: '.$bank.'. Your ban lasts until '.$bant.'."); window.open("login.php","_self");</script>';
    

    In short, you shouldn't have used brackets twice in the JavaScript alert message.

    Addition: Do not forget to echo the notice in the end. The excerpt of your PHP script doesn't show me anything like that. If you want to show your homepage after the ban check, just use the die-function to output a message and terminate the current script if the user is banned. In your case, just add the following after having defined the variable $notice:

    die($notice);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • dtng5978 2011-04-24 13:32
    关注

    You are providing too much information to the user, all they need to know is that they are banned, not the type of ban.

    if (banned)
    {
      ajax.display("Ban HAMMER!!");
    }
    else
    {
      user.logon();
      redirect("location: home.php");
    }
    
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 这个要用一维热方程但是我不知道怎么运用这个公式
  • ¥15 OpenFOAM多孔介质传热模型建模
  • ¥15 QT 实现 RSTP 语音对讲功能
  • ¥50 AES魔改之后的安全性关于PRF(相关搜索:密码学)
  • ¥15 用C语言写的一个程序遇到了两个问题第一是偏移正确但读取不到坐标,第二个问题是自己定义的函数实现不了获取指定进程模块。
  • ¥15 在安装Anaconda时总是闪退怎么办?
  • ¥15 对图中电路进行以下几个方面的分析
  • ¥15 对图中电路进行以下几个方面的分析
  • ¥15 对图中电路进行以下几个方面的分析
  • ¥15 对图中电路进行以下几个方面的分析