Php 我如何才能使我的网站登录表工作?

Php 我如何才能使我的网站登录表工作?,php,authentication,Php,Authentication,我最近尝试为我的社交网站创建一个登录表单。它工作,但不是我想要的方式。我只需要输入一个用户名,就可以登录了。我想它是用户名和密码,因为安全。我以前尝试过解决这个问题,但没有任何效果。所以我想看看我是否能在这里得到帮助 signin.php: <html> <head> <title>Interpage</title> </head> <body bgcolor="#E6E6FA"> <h1><center

我最近尝试为我的社交网站创建一个登录表单。它工作,但不是我想要的方式。我只需要输入一个用户名,就可以登录了。我想它是用户名和密码,因为安全。我以前尝试过解决这个问题,但没有任何效果。所以我想看看我是否能在这里得到帮助

signin.php:

<html>
<head>
<title>Interpage</title>
</head>
<body bgcolor="#E6E6FA">

<h1><center>Login</center></h1>

<form action="process.php" method="post">
<p align="center">
<input type="text" name="username" size="35" id="Username" placeholder="Username" /></p>
<br></br>
<p align="center">
<input type="password" name="password" size="35"  id="Password" placeholder="Password" /></p>
<center>
<input type="submit" name="login" value="Log In"/></center>
<h3 style="font-size: 20px"><a href="register.php">Go Back To Home Screen</a></h3>  
</form> 
</body>
</html>

间皮
登录



process.php:

<?php
include("db.php");

if ( isset( $_POST['login'] ) ) {

$username = $_POST['username'];
$pw = $_POST['StorePassword'];

$query = mysqli_query($conn, "SELECT * FROM users WHERE username='".$username."'");

if ( mysqli_num_rows($query) > 0 ) {
    while ( $row = mysqli_fetch_assoc( $query ) ) {
    if ( $row['StorePassword'] == $StorePassword ) {
       header("Location: home.php"); 
        } else { 
            echo "Wrong password"; 
        }
    }
} else {
    echo "User not found <br />";
}

if ( !isset($_POST['username'], $_POST['StorePassword']) ) {

die ('You must enter a username and password! <a href= signin.php>Try again</a> ');

}   else {

}
}
?>

这是一个相当简单的问题。您可以使用
会话
让用户登录


让我们从头开始。在页面顶部,即在
之后立即将if($row['StorePassword']==$StorePassword)更改为if($row['StorePassword']==$pw),也使用准备好的语句,因为您对SQL注入开放,最后,但也是非常导入的,从不存储纯文本密码。我不在我的注册表中,它;'正在哈希可能的查询副本还需要密码:“从username=”、“$username.”和password=”的用户中选择*$嗯
if ( $row['StorePassword'] == $StorePassword ) {

    ....

    $_SESSION[ 'logged_in' ] = true;
    $_SESSION[ 'user_name' ] = $username;

// ... continuing your logic  
if ( $_SESSION['logged_in'] && isset( $_SESSION['user_name'] ) {
    header("Content-type: text/html");
} else {
    die( "The user is not logged in. Click <a href=\"login.php\">here</a> to login" );
}