ログインフォームを介して渡されたユーザー名とパスワードを一致させ、セッションを作成し、セッション変数を通過させ、ユーザーを別のページにリダイレクトしようとするログインスクリプトを作成しました。
私は OOP PDO アプローチ スタイルを使用しています。
ユーザーを登録するとき、PHP crypt メソッドを使用してパスワードを暗号化します。ただし、ログインしようとすると、ステートメントが false として返されます。公平を期すために、何が間違っているのかわかりません。おそらく、パスワードを間違って解読しているのかもしれませんが、わかりません。
false と言うときは、if ステートメントのエコーを意味します
Invaild username or password. Try again
ヘルプやアイデアは大歓迎です。よろしくお願いします。
index.php
<form id="loginForm" method="POST" action="classes/class.Login.php">
<input type="text" id="username" name="username" placeholder="Username"/>
<input type="password" id="password" name="password" placeholder="Password" class="showpassword"/>
<input type="submit" name="submit" value="Log in"/>
クラス/class.Login.php
public function loginuser() {
$username = $_POST['username'];
$password = $_POST['password'];
$stmt = $this->pdo->prepare("SELECT * FROM users WHERE username = :username AND password = :password LIMIT 1");
$stmt->bindValue(":username", $username);
$stmt->bindValue(":password", crypt($password));
$stmt->execute();
if ($stmt->fetch())
{
$_SESSION['authorized'] = true;
$_SESSION['username'] = $username;
header("Location: testloginrequired.php");
}
else
{
echo "Invaild username or password. Try again";
}
}// end loginuser