私はユーザ名とパスワードでログインしようとすると、私を覚えています。ログインして再度ログインページに戻ると、そこにユーザ名とパスワードは表示されません。私は間違って何をしているのですか?PHPで動作していないことを記憶してください
<?php
$title = "Login Page";
$heading = "Login Form";
include "includes/home_page_header.php";
?>
<?php
$cookie_username = $cookie_password = "";
if(isset($_POST['login']))
{
//echo "<pre>"; print_r($_POST); echo "</pre>";die;
if(!empty($_POST['cookie_username']) && !empty($_POST['cookie_password']))
{
$cookie_username = $_POST["cookie_username"];
$cookie_password = $_POST["cookie_password"];
$sql_users="SELECT * FROM users WHERE username='$username' AND password='$password'";
$res_users = mysqli_query($link,$sql_users);
if(mysqli_num_rows($res_users) > 0)
{
$_SESSION["Username"]= $cookie_username;
$_SESSION["Password"]= $cookie_password;
header('Location:http://localhost/sample/home_page.php');
}
else
{
echo 'The username or password are incorrect!';
}
}
if($_POST['rememberMe'] =='on')
{
setcookie('cookie_username', $cookie_username, time() + (86400 * 30));
setcookie('cookie_password', $cookie_password, time() + (86400 * 30));
if(!isset($_COOKIE['cookie_username']))
{
echo "Cookie named '" . $cookie_username . "' is not set!";
}
else
{
echo "Cookie '" . $cookie_username . "' is set!<br>";
echo "Value is: " . $_COOKIE['cookie_username'];
}
}
}
?>
<table class="login_table">
<form name="login" action="" method="post">
<tr>
<td>User Name :-</td>
<td><input type="text" name="cookie_username" value="<?php echo $cookie_username;?>"/></td>
</tr>
<tr>
<td>Password :-</td>
<td><input type="password" name="cookie_password" value="<?php echo $cookie_password;?>"/></td>
</tr>
<tr>
<td></td>
<td><input type="checkbox" name="remember" <?php if(isset($_COOKIE['remember'])) {
echo 'checked="checked"';
}
else {
echo '';
}
?> >Remember Me
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="login" value="Login"/>
<input type="submit" name="cancel" value="Cancel"/></td>
</tr>
</form>
</table>
パスワードをクッキーに保存しないでください。 – syck
'$ cookie_username'変数は、ログインページから来た場合にのみ設定されますが、再度入力した場合は設定されません。 – syck
ログインシステムとセッションシステムは非常に機密です。ベストプラクティスに関する多くの論理と議論があります。あなたの質問に基づいて、基本的な暗号化方法、衛生、適切な機密データ保管技術について最初に学ぶことをお勧めします。 – jjonesdesign