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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效