当用户被禁止时,回显错误通知 [英] When a user is banned it echo's the wrong notice out

查看:75
本文介绍了当用户被禁止时,回显错误通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户被禁止时,它应该回显被禁止的回显,但是回显是失败的登录回显,如果有人可以帮助我,那么我已经搞砸了。

When the user is banned it should echo out the banned echo but instead it echo's out the Failed login echo, Somewhere along the line I've messed something up if someone could assist me with this much appreciated.

下面的我的PHP代码。

My PHP Code Below.

<?php
          if (!($user -> LoggedIn()))
          {
            if (isset($_POST['logINBoss']))
                    {
                        $captcha = htmlspecialchars($_POST["g-recaptcha-response"]);
                        $secret = $odb->query("SELECT `google_secret` FROM `admin` LIMIT 1")->fetchColumn(0);
                        $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secret."&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
                        $response = json_decode($response);
                        if (!$captcha || $response->success == false)
                        {
                        echo '<center><div class="alert alert-icon alert-danger alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><i class="mdi mdi-check-all"></i>Invalid Captcha Code Entered!</div></center>';
                        } else {
                        $username = htmlspecialchars($_POST['username']); 
                        $password = htmlspecialchars($_POST['password']);
              $Errors = array();
              if (!ctype_alnum($username) || strlen($username) < 1 || strlen($username) > 15)
              {
                $Errors[] = '<center><div class="alert alert-icon alert-danger alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><i class="mdi mdi-check-all"></i>Username Must Be  Alphanumberic And 4-15 characters in length</div></center>';
              }
              if (empty($username) || empty($password))
              {
                $Errors[] = '<center><div class="alert alert-icon alert-danger alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><i class="mdi mdi-check-all"></i>Fill in all fields</div></center>';
              }
              if (empty($Errors))
              {
        $SQLCheckLogin = $odb->prepare("SELECT COUNT(*) FROM `users` WHERE `username` = :username AND `password` = :password");
        $SQLCheckLogin -> execute(array(':username' => $username, ':password' => SHA1($password)));
        $countLogin = $SQLCheckLogin -> fetchColumn(0);
        if ($countLogin == 1)
        {
            $SQLGetInfo = $odb->prepare("SELECT `username`, `ID`, `status` FROM `users` WHERE `username` = :username AND `password` = :password");
            $SQLGetInfo -> execute(array(':username' => $username, ':password' => SHA1($password)));
            $userInfo = $SQLGetInfo -> fetch(PDO::FETCH_ASSOC);
        if ($countLogin == 1)
        {
        $SQL = $odb->prepare("SELECT `status` FROM `users` WHERE `username` = :username");
        $SQL->execute(array(':username' => $username));
        $status = $SQL->fetchColumn(0);
        if($status == 1)
        {
        $SQL = $odb->prepare("SELECT `reason` FROM `bans` WHERE `username` = :username");
        $SQL->execute(array(':username' => $username));
        $ban = $SQL->fetchColumn(0);
        die('<span style="color:red;">You are banned. Reason:</span> ' . htmlspecialchars($ban)); 
        }
                $logAddr = $odb->prepare("INSERT INTO `loginip` (`username`,`ip`,`date`,`http_agent`) VALUES (:user, :ip, UNIX_TIMESTAMP(NOW()), :agent);");
                $logAddr->execute(array( ":user" => $username, ":ip" => $_SERVER['REMOTE_ADDR'], ":agent" => $_SERVER['HTTP_USER_AGENT']));
                $_SESSION['username'] = $userInfo['username'];
                $_SESSION['ID'] = $userInfo['ID'];
                echo '<center><div class="alert alert-icon alert-success alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><i class="mdi mdi-check-all"></i>You have been logged in successfully..</div></center><meta http-equiv="refresh" content="3;url=index.php">';
                  }
                  else
                  {
                  echo '<center><div class="alert alert-icon alert-danger alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><i class="mdi mdi-check-all"></i>You are banned for Reason...</div></center>';        
                  }
                  }
                else
                {
                  echo '<center><div class="alert alert-icon alert-danger alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><i class="mdi mdi-check-all"></i>Login Failed!!</div></center>';
                }
              }
              else
              {
                  echo '';
                foreach($Errors as $Error)
                {
                  echo ''.htmlspecialchars($Error).'';
                }
                echo '</div>';
              }
            }
          }
          }
          ?>

应回显此

                      echo '<center><div class="alert alert-icon alert-danger alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><i class="mdi mdi-check-all"></i>You are banned for Reason...</div></center>';        

对于被禁用户。

但是

 echo '<center><div class="alert alert-icon alert-danger alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><i class="mdi mdi-check-all"></i>Login Failed!!</div></center>';

但是有没有人可以看到问题的帮助,甚至帮助我纠正问题。

but is there anyone who can see the issue help or even navigate me on correcting it.

推荐答案

将此行放置在 if 块之外

$SQL = $odb->prepare("SELECT `status` FROM `users` WHERE `username` = :username");
        $SQL->execute(array(':username' => $username));
        $status = $SQL->fetchColumn(0);

在其他部分,wahich说登录失败这样做

and in else part whaich says login failed do this

else // else for login failed
{

if($status == 1)
        {
        $SQL = $odb->prepare("SELECT `reason` FROM `bans` WHERE `username` = :username");
        $SQL->execute(array(':username' => $username));
        $ban = $SQL->fetchColumn(0);
echo '<center><div class="alert alert-icon alert-danger alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><i class="mdi mdi-check-all"></i>You are banned for Reason...</div></center>';        
        die('<span style="color:red;">You are banned. Reason:</span> ' . htmlspecialchars($ban)); 
        }  

                  echo '<center><div class="alert alert-icon alert-danger alert-dismissible fade in" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button><i class="mdi mdi-check-all"></i>Login Failed!!</div></center>';
                }

您还尝试将禁止打印为有效也有用户

you also tried to print that banned for valid users too

这篇关于当用户被禁止时,回显错误通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆