简体   繁体   English

登录不检查密码是否错误

[英]Login not checking if password is wrong

So for some reason if the password is correct it knows and takes the user to the correct user account, but if the pass is wrong, it wont log them in but still takes them to the account page that isn't logged in.因此,出于某种原因,如果密码正确,它知道并将用户带到正确的用户帐户,但如果密码错误,它不会登录,但仍会将它们带到未登录的帐户页面。

Can someone please help me out to not re-direct them if the password is wrong如果密码错误,有人可以帮助我不要重定向他们吗

<?php
session_start();
//$connection = mysqli_connect('localhost', 'root', '');
$connection = mysqli_connect("pdb18.awardspace.net","*****","******","*****");
if (!$connection){
    die("Database Connection Failed" . mysqli_error($connection));
}
$select_db = mysqli_select_db($connection, '******');
if (!$select_db)
    {
        die("Database Selection Failed" . mysqli_error($connection));
    }
    $username=trim($_POST['username']);
    $password=trim($_POST['password']);

    //$encoded_password = base64_encode($password);

$sql = "SELECT * from register where Username='".$username."' and Password='".$password."'";
$result = mysqli_query($connection, $sql) or die(mysqli_error($connection));
$result = $con->query($sql);
$count = mysqli_num_rows($result);
//echo $count;
    if ($count == 1){
        while($row = $result->fetch_assoc()) {
                $id=$row['id'];
        }

        $_SESSION['User'] = $username;
                $_SESSION['UserId'] = $id;
        echo "valid";
    }
    else{
        echo "Invalid";
    }

?> 

Remove this line:删除这一行:

$result = $con->query($sql);

You are using procedural functions, mysqli_* .您正在使用过程函数mysqli_*

This part of code $con->query is OOP style, which you are not using in your code, and overwritting the value o $result variable.这部分代码$con->query是 OOP 风格,你没有在你的代码中使用它,并覆盖了$result变量的值。 You can use both styles, but you should use the same connection, or $connection in your case.您可以使用这两种样式,但您应该使用相同的连接,或者在您的情况下使用$connection

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM