0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PHP 学習リファレンス - Cookie

Posted at

コード

ref: https://blog.csdn.net/u011781769/article/details/48470697

<?php
    if ($_COOKIE ['uname'] != '') {
        $CKUNAME = $_COOKIE ['uname'];
    }
    if ($_COOKIE ['pwd'] != '') {
        $CKPWD = $_COOKIE ['pwd'];
    }
    echo "\$CKUNAME:" . $CKUNAME;
    echo '<br>';
    echo "\$CKPWD:" . $CKPWD;
?>

<!DOCTYPE html>

<head>
    <title>Cookie</title>
    <h1> Cookie</h1>
</head>
<hr />
<body>

<form action = "<?php echo htmlspecialchars($_SERVER["PHP_SELF"])?>" method = "POST">
Name:   <input type="text" name="uname" id="uname" value="<?php echo $CKUNAME;?>"><br>
PW:    <input type="password" name="pwd" id="pwd" value="<?php echo $CKPWD;?>"><br>
    <input name="remember" type="checkbox" value="1" checked = <?php if($CKUNAME!=''){echo "checked";}?>> 记住我! 
    Debug : <?php echo "\$CKUNAME:" .  $CKUNAME?>
    <br>
    <input type="submit" name="button" id="button" value="登录" /> <br>
</form>
<hr />

<?php
    // 登录,将用户名和密码存入到COOKIE
    if ($_POST ['button'] != '') 
    {
        $uname = $_POST ['uname'];
        $pwd = $_POST ['pwd'];
         
        // 如果输入的加密密码和COOKIE中不一样,那么就加密
        if ($pwd != $CKPWD) {
            $pwd = md5 ( $pwd );
        }
        $remember = $_POST ['remember'];
        if ($remember == 1) {
            setcookie ( "uname", $uname, time () + 3600 * 24 * 30 );
            setcookie ( "pwd", $pwd, time () + 3600 * 24 * 30 );
        }
    }
?>
</body>

</html>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?