Log in interface
<?PHPHeader(' Content-type:text/html;charset=utf-8 '); if(isset($_cookie[' username ']) &&$_cookie[' username ']=== ' Zeng '){ Exit(' You are already logged in, please do not log in again '); } if(isset($_post[' Submit '])){ if(isset($_post[' username ']) &&isset($_post[' Password ']) &&$_post[' username ']== ' zengguanling ' &&$_post[' Password ']== ' 123456 ' ){ if(Setcookie(' username ',$_post[' username '], Time() +3600)){ Header(' location:skip.php?url=index.php&info= Login success! Jump to the first face after 3 seconds '); } Else { Echo' Cookie settings failed '; } } Else { Header(' location:skip.php?url=login.php&info= Sorry, user name Live password fill error! Jump to login page in 3 seconds); } }? ><! DOCTYPE html>Name:<input type= "text" name= "username"/>Password:<input type= "password" name= "password"/> <input type= "Submit" name= "submit" value= "Log In"/> < ;/form> </body>Jump Processing Page skip.php
<? PHP if (! isset ($_get[' url ']) | | ! isset ($_get[' Info '])) { exit(); }? ><! DOCTYPE html>$_get[' url ']? > "/> <title> in jump ...</title> Echo $_get [' Info ']?></div> </body>
Log In Home index.php
<? PHP Header (' Content-type:text/html;charset=utf-8 '); if (isset($_cookie$_cookie[' username ']=== ' zeng ') { echo "Hello! {$_cookie[' username ']}, welcome back! "; Echo "<a href= ' logout.php ' > Logout </a>"; } Else { echo "<a href= ' login.php ' > Please log in </a>"; }? >
Logoff Processing Interface logout.php
<?PHPHeader(' Content-type:text/html;charset=utf-8 '); if(isset($_cookie[' username ']) &&$_cookie[' username ']=== ' Zeng '){ if(Setcookie(' username ',$_post[' username '], Time()-3600)){ Header(' location:skip.php?url=index.php&info= logout success, is jumping! ‘); }Else{ Header(' location:skip.php?url=index.php&info= logoff failed, please try again later! ‘); } }?>
PHP User Login and logout (cookie)