Phpsession application instance logon verification

Source: Internet
Author: User
Tags php for beginners
& Lt; html & gt; & lt; head & gt; & lt; title & gt; Login & lt;/title & gt; & lt; metahttp-equiv = & quot; content-Type & quot; content = & quot; text/html; charset = gb2312 & quot; & gt; & lt;/head &

 
 
Login 
 
 
 
 
 


--------------------------------------------------------------------

@ Mysql_connect ("localhost", "root", "1981427") // you must connect to the database server before selecting a database.
Or die ("database server connection failed ");
@ Mysql_select_db ("test") // select the database mydb
Or die ("The database does not exist or is unavailable ");
// Obtain user input
$ Username = $ _ POST ['username'];
$ Passcode = $ _ POST ['passcode'];
// Execute an SQL statement to obtain the Session value
$ Query = @ mysql_query ("select username, userflag from users"
. "Where username = '$ username' and passcode =' $ passcode '")
Or die ("SQL statement execution failed ");
// Determine whether the user exists and the password is correct
If ($ row = mysql_fetch_array ($ query ))
{
Session_start (); // indicates the start of the Session.
// Determine whether the user's permission information is valid. if the value is 1 or 0, the permission information is valid.
If ($ row ['userflag'] = 1 or $ row ['userflag'] = 0)
{
$ _ SESSION ['username'] = $ row ['username'];
$ _ SESSION ['userflag'] = $ row ['userflag'];
Echo "Welcome to log on. Click here to enter the welcome page ";
}
Else // output error message if the permission information is invalid
{
Echo "incorrect user permission information ";
}
}
Else // if the user name and password are incorrect, an error is returned.
{
Echo "incorrect user name or password ";
}
?>

--------------------------------------------------------------
Unset ($ _ SESSION ['username']);
Unset ($ _ SESSION ['passcode']);
Unset ($ _ SESSION ['userflag']);
Echo "logout successful ";
?>

---------------------------------------------------------------

Session_start ();
If (isset ($ _ SESSION ['username'])
{
@ Mysql_connect ("localhost", "root", "1981427") // you must connect to the database server before selecting a database.
Or die ("database server connection failed ");
@ Mysql_select_db ("test") // select the database mydb
Or die ("The database does not exist or is unavailable ");
// Obtain the Session
$ Username = $ _ SESSION ['username'];
// Execute the SQL statement to obtain the userflag value
$ Query = @ mysql_query ("select userflag from users"
. "Where username = '$ username '")
Or die ("SQL statement execution failed ");
$ Row = mysql_fetch_array ($ query );
// Compare the permission information in the current database with that in the Session. if the permission information is different, update the Session information.
If ($ row ['userflag']! = $ _ SESSION ['userflag'])
{
$ _ SESSION ['userflag'] = $ row ['userflag'];
}
// Output different welcome information based on the Session value
If ($ _ SESSION ['userflag'] = 1)
Echo "welcome administrator". $ _ SESSION ['username']. "log on to the system ";
If ($ _ SESSION ['userflag'] = 0)
Echo "welcome". $ _ SESSION ['username']. "log on to the system ";
Echo "logout ";
}
Else
{
Echo "you are not authorized to access this page ";
}
?> I also reprinted other people's PHP for beginners. I haven't tested it on the computer yet. collect it first.

From: http://phpstart.php100.com/apps-htm-q-diary-a-detail-did-7373.html

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.