美文网首页Web前端之路
基于cookie记住用户名

基于cookie记住用户名

作者: 我是何宝荣呀 | 来源:发表于2019-09-25 11: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');

相关文章

网友评论

    本文标题:基于cookie记住用户名

    本文链接:https://www.haomeiwen.com/subject/pdqluctx.html