まず、助けてくれてありがとう!私はこのサイトに参加したばかりですが、多くの皆さんがとても親切で辛抱強くサポートしてくれました! (:
だから、私の問題はログインフォームにあります。間違った情報を入力してもログインできます。私はpdoが初めてで、すべてのMysql関数をpdoに変換したばかりなので、どこかで間違っていたと確信しています。
これが私のログインスクリプトです:
<?php
//Login script
if (isset ($_POST["user_login"]) && isset($_POST["password_login"])) {
$user_login = preg_replace('#[^A-Za-z0-9]#i', '', $_POST["user_login"]); //filter everything but numbers and letters
$password_login = preg_replace('^A-Za-z0-9)#i','', $_POST["password_login"]); //filter everything but numbers and letters
$password_login=md5($password_login);
$db = new PDO('mysql:host=localhost;dbname=socialnetwork', 'root', 'password');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT id FROM users WHERE username = '$user_login' AND password = '$password_login' LIMIT 1";
$db->prepare($sql);
if ($db->execute(array(
'$user_login' => $user_login,
'$password_login' => $password_login))); {
if ($sql->rowCount() > 1){
while($row = $sql->fetch($sql)){
$id = $row["id"];
}
$_SESSION["id"] = $id;
$_SESSION["user_login"] = $user_login;
$_SESSION["password_login"] = $password_login;
exit("<meta http-equiv=\"refresh\" content=\"0\">");
} else {
echo 'Either the password or username you have entered is incorrect. Please check them and try again!';
exit();
}
}
}
?>
フォームは次のとおりです。
<form action="home.php" method="post">
<center><input type ="text" size="25" name="User_login" id="user_login" placeholder="username"/>
<input type ="password" size="25" name="user_password" id="user_password" placeholder="password"/><br />
<input type ="submit" name="button" id="button" value="login to your account!"/></center>
</form>
これを修正する方法についてのアイデアはありますか?