我正在尝试登录用户,然后重定向它们,登录正在传递,因为我得到1回来但是它没有使用标题函数重定向
php code bellow
<?php
session_start();
$conn = new PDO('mysql:host=localhost;dbname=root', 'root', 'root');
if(isset($_POST['username'],$_POST['password']))
{
$username=$_POST['username'];
$password=$_POST['password'];
$stmt = $conn->prepare("SELECT * FROM User WHERE Username = ? AND Password = ?"); // SQL Statement that selects all the Users credentials.
$stmt->bindParam(1, $username, PDO::PARAM_STR,45); // the bind parameter will insert the username variable into the SQL Statement.
$stmt->bindParam(2, $password, PDO::PARAM_STR,45); // the bind parameter will insert the password variable into the SQL Statement.
$stmt->execute(); // This executes the sql statements above.
$count = $stmt->rowCount(); // This produces a row count to see if the credentials used are in the database.
echo $count;
if($count == 1) { // this if statement will check the users credentials found in the Database.
$_SESSION['loggedin'] = "1";
header("location: Homepage.php", true, 301 ); // if successfull the user shall be directed to the homepage of RealReels
}
else { // the else statement is the outcome if the users credentials not found in the Database.
$_SESSION['loggedin'] = "0";
header ("Location: login.php"); // if not succcessful the user is linked to the Log_in.php error page.
}
}
?>
html表单
<form name="input" action="Log_in_validation.php" method="POST">
<label for="User_name" >Username:</label>
<input type="text" name="username">
<label for="Password" >Password: </label>
<input type="password" name="password">
<input type="submit" value="Log In"/>
</form>