PHP User Login and logout (cookie)

Source: Internet
Author: User
Tags setcookie

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"/> &lt ;/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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.