php_login_cookie

<?php

if ($_GET[out]) {
    setcookie("id",'');
    setcookie("pass", '');
    echo "<script>location.href='login.php'</script>";
}

if ($_POST[name] && $_POST[password]) {
    setcookie("id", $_POST[name],  time()+3600);
    setcookie("pass", $_POST[password],  time()+3600);
    echo "<script>location.href='login.php'</script>";
}

if ($_COOKIE[id] && $_COOKIE[pass]) {
    echo "<br>用户名:".$_COOKIE[id];
    echo "<br>密码:".$_COOKIE[pass];
    echo "<br><a href='login.php?out=out'>退出</a>";
}

?>

<form action="" method="post">
    用户ID:
    <input type="text" name="name" ><br/><br/>
    密码:
    <input type="password" name="password"  ><br> <br>
        <input type="submit" value="登陆">
</form>
 

你可能感兴趣的:(PHP)