基于cookie记住用户名
2019-09-25 本文已影响0人
我是何宝荣呀
提交界面
<?php
$username = isset($_COOKIE['username']) ? $_COOKIE['username'] : '';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>用户登陆</title>
</head>
<body>
<form action="login.php" autocomplete="off" method="post">
<table>
<tr>
<td>用户</td>
<td><input type="text" name="username" value="<?php echo $username ?>"></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td></td>
<td><button>登陆</button></td>
</tr>
</table>
</form>
</body>
</html>
接收界面
<?php
if (empty($_POST['username'])||empty($_POST['password'])) {
exit('请正确输入表单内容!');
}
$username=$_POST['username'];
setcookie('username',$username);
header('Location: main.php');