The purpose of building a website is the integrity of the function. One of these features is the implementation of user login verification. Let's give you a detailed introduction to the
Sample PHP Cookie Login Verification code:
- < html>
- < head>
- < title>Login< /title>
- < meta http-equiv="Content-type"
content="text/html; charset=gb2312 ">
- < /head >
- < body>
- < form name = Form1 " method = Post "
action = "login.php" ;
- < table width = "border" = "0" align="center"
cellpadding="2" cellspacing="2" >
- < tr>
- < TD width = "150" > < Div align = "right" span class= "tag" > ;
user name: < /div > < /td ;
- < td width="Max">< input type="text"
name="username">< /td >
- < /tr >
- < tr>
- < td>< div align ="right"> Password:< /div> < /td>
- < td>< input type= "password" name="passcode"> < /td >
- < /tr >
- < tr>
- < TD > < Div align = Right " ; Cookie Save time: < /div > < /td ;
- < td>< Select name ="Cookie " id="cookie">
- < option value="0" selected> Browser Process < /option>
- < option value="1"> save 1 days < /option >
- < option value="2"> Save 30 days < /option >
- < option value="3"> Save 365 days < /option >
- < /select >< /td >
- < /tr >
- < /table >
- < p align="center">
- < input type = "Submit" Name = "Submit" value="Submit">
- < input type = "reset" name = "Reset" value="Reset">
- < / P >
- < /form >
- < /body >
- < /html >
- < ? PHP
- @mysql_connect ("localhost", "root", "1981427")
You need to connect to the database server before selecting a database
- Or Die ("Database server Connection Failed");
- @mysql_select_db ("test")//Select Database MyDB
- Or Die ("database does not exist or is not available");
- Get user input
- $ username = $_post[' username '];
- $ Passcode = $_post[' passcode '];
- $ Cookies = $_post[' Cookie '];
- Execute SQL statement
- $ Query = @mysql_query ("Select Username,
Userflag from Users "
- ." Where username = ' $username ' and
Passcode = ' $passcode ' ")
- Or Die ("SQL statement execution failed");
- Determine if the user exists, the password is correct
- if ($row = mysql_fetch_array($query))
- {
- if ($row [' userflag '] = = 1 or $row [' userflag '] = = 0)
Determine if user rights information is valid
- {
- Switch ($cookie)//Set cookie save time according to user's choice
- {
- Case 0://Save cookie for browser process
- Setcookie ("username", $row [' username ']);
- Break
- Case 1://Save 1 days
- Setcookie ("username", $row [' username '],
Time () +24*60*60);
- Break
- Case 2://Save 30 days
- Setcookie ("username", $row [' username '],
Time () +30*24*60*60);
- Break
- Case 3://Save 365 Days
- Setcookie ("username", $row [' username '],
Time () +365*24*60*60);
- Break
- }
- Header ("location:main.php");
Auto Jump to main.php
- }
- Else
- {
- echo "User rights information is incorrect";
- }
- }
- Else
- {
- echo "User name or password error";
- }
- ?>
PHP Cookie Login Verification code example:
- < ? PHP
- Session_Start ();
- if (isset ($_cookie[' username '))
- {
- @mysql_connect ("localhost", "root", "1981427")
- You need to connect to the database server before selecting a database
- Or Die ("Database server Connection Failed");
- @mysql_select_db ("test")//Select Database MyDB
- Or Die ("database does not exist or is not available");
- Get session
- $ username = $_cookie[' username '];
- Execute SQL statement to get Userflag value
- $ Query = @mysql_query ("Select
Userflag from Users "
- ." Where username = ' $username '")
- Or Die ("SQL statement execution failed");
- $ Row = Mysql_fetch_array ($query);
- Obtaining User rights Information
- $ Flag = $row [' Userflag '];
- Output a different welcome message based on the value of Userflag
- if ($flag = = 1)
- echo "Welcome administrator". $_session[' username '
." Login System ";
- if ($flag = = 0)
- echo "Welcome user". $_session[' username '
." Login System ";
- echo " < a href="logout.php"
href = "logout.php" > Logout < /A > ";
- }
- Else
- {
- echo "You do not have permission to access this page";
- }
- ?>
- < ? PHP
- Setcookie ("username");
- echo "Logout success";
- ?>
The implementation of the above-mentioned timely PHP cookie login verification.
http://www.bkjia.com/PHPjc/445946.html www.bkjia.com true http://www.bkjia.com/PHPjc/445946.html techarticle The purpose of building a website is the integrity of the function. One of these features is the implementation of user login verification. Below we will give you a detailed description of the PHP cookie login verification Code ...