PHP session application instance-Logon Verification

Source: Internet
Author: User

 <HTML> <br/> <pead> <br/> <title> login </title> <br/> <meta http-equiv = "Content-Type" content =" text/html; charset = gb2312 "> <br/> </pead> </P> <p> <body> <br/> <form name =" form1 "method =" Post "Action = "login. PHP "> <br/> <Table width =" 300 "border =" 0 "align =" center "cellpadding =" 2 "cellspacing =" 2 "> <br/> <tr> <br/> <TD width = "150"> <Div align = "right"> User Name: </div> </TD> <br/> <TD width = "150"> <input type = "text" name = "username"> </TD> <br/> </tr> <br/> <TD> <Div align = "right"> password: </div> </TD> <br/> <TD> <input type = "password" name = "passcode"> </TD> <br/> </tr> <br/> <tr> <br/> <TD> <Div align = "right"> cookie Retention Time: </div> </TD> <br/> <TD> <select name = "cookie" id = "cookie"> <br/> <option value = "0" selected> browser Process </option> <br/> <option value = "1"> Save for 1 day </option> <br/> <option value = "2"> Save for 30 days days </option> <br/> <option value = "3"> Save for 365 days </option> <br/> </SELECT> </TD> <br/> </tr> <br/> </table> <br/> <p align = "center"> <br/> <input type = "Submit" name = "Submit" value = "Submit"> <br/> <input type = "reset" name = "reset" value = "reset"> <br/> </P> <br/> </form> <br/> </body> <br/> </ptml> <br/>

<? Php <br/> @ mysql_connect ("localhost", "root", "1981427 ") // before selecting a database, connect to the database server <br/> or die ("database server connection failed"); <br/> @ mysql_select_db ("test ") // select the database mydb <br/> or die ("the database does not exist or is unavailable "); <br/> // obtain user input <br/> $ username = $ _ post ['username']; <br/> $ passcode = $ _ post ['passcode']; <br/> // run the SQL statement to obtain the session value <br/> $ query = @ mysql_query ("select username, userflag from users" <br/>. "Where username = '$ username' and passcode = '$ Passcode' ") <br/> or die (" SQL statement execution failed "); <br/> // determines whether the user exists, correct password <br/> if ($ ROW = mysql_fetch_array ($ query) <br/>{< br/> session_start (); // indicates the start of the session <br/> // determines whether the user's permission information is valid, valid if it is 1 or 0 <br/> if ($ row ['userflag'] = 1 or $ row ['userflag'] = 0) <br/> {<br/> $ _ session ['username'] = $ row ['username']; <br/> $ _ session ['userflag'] = $ row ['userflag']; <br/> echo "<a href =" Main. PHP "mce_href =" Main. PHP "> welcome to log on. Click here to enter Welcome Page </a> "; <br/>}< br/> else // error message output if the permission information is invalid <br/> {<br/> echo "incorrect user permission information "; <br/>}< br/> else // if the user name and password are incorrect, an error is returned. <br/>{< br/> echo "incorrect user name or password"; <br/>}< br/>?> <Br/>

<? Php <br/> unset ($ _ session ['username']); <br/> unset ($ _ session ['passcode']); <br/> unset ($ _ session ['userflag']); <br/> echo "logout successful"; <br/>?>

<? Php <br/> session_start (); <br/> If (isset ($ _ session ['username']) <br/>{< br/> @ mysql_connect ("localhost", "root", "1981427 ") // before selecting a database, connect to the database server <br/> or die ("database server connection failed"); <br/> @ mysql_select_db ("test ") // select the database mydb <br/> or die ("the database does not exist or is unavailable "); <br/> // obtain the session <br/> $ username = $ _ session ['username']; <br/> // run the SQL statement to obtain the userflag value <br/> $ query = @ mysql_query ("select userflag from users" <br/>. "Where username = '$ Username' ") <br/> or die (" SQL statement execution failed "); <br/> $ ROW = mysql_fetch_array ($ query ); <br/> // compare the permission information in the current database with that in the session. If different, update the session information. <br/> if ($ row ['userflag']! = $ _ Session ['userflag']) <br/>{< br/> $ _ session ['userflag'] = $ row ['userflag']; <br/>}< br/> // output different welcome information based on the session value <br/> if ($ _ session ['userflag'] = 1) <br/> echo "Welcome to administrator ". $ _ session ['username']. "log on to the system"; <br/> if ($ _ session ['userflag'] = 0) <br/> echo "welcome ". $ _ session ['username']. "log on to the system"; <br/> echo "<a href =" logout. PHP "mce_href =" logout. PHP "> logout </a>"; <br/>}< br/> else <br/> {<br/> echo "You are not authorized to access this page "; <br/>}< br />?> <Br/>

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.