PHP user identity authentication (4)

Source: Internet
Author: User
Tags php source code

Introduction: This is a detailed page on PHP user identity authentication (4). It introduces PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 327686 'rolling = 'no'>

PHP user identity authentication (4)
Popcorn 2001 www.westxj.net
Hello everyone, the previous sections have discussed how to write a program based on HTTP single-user and multi-user password verification. This method is best for pages requiring authentication. However, this authentication cannot be used in CGI Mode PHP or in IIS. Therefore, we can use sessions to store user information between different pages for verification purposes.
Session refers to the time interval between an end user and the Interaction System. It usually refers to the time between registration and entry into the system and cancellation and exit of the system. The session function is used to define global variables through PHP scripts, so that all PHP scripts of the global variables in the same session are valid.
The user login form handler is as follows:
<?
$ Db = mysql_connect ("localhost", "root", "1234 ");
// Connect to the Database Server
Mysql_select_db ("Jane", $ dB );
// Connect to the database
$ Result = mysql_query ("select * from user where name = '$ name' and Password =' $ pass'", $ dB );
// Send the query string to the database
If ($ myrow = mysql_fetch_row ($ result ))
// If the record pointer is true
{
Session_start (); // Session Initialization
Session_register ("user"); // register the user variable
$ User = $ myrow ["user"];
Echo "Verification Successful! ";
}
Else
{
Echo "authentication failed! ";
}
?>
Add the following program to the beginning of the page to be protected:
<?
Session_start ();
If (! Session_is_registered ("user") // check whether the session variable is registered
{
Echo "Verification Failed. Illegal logon! ";
}
Else
{
......

}
?>

More articles on PHP user identity authentication (IV)

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/327686.html pageno: 12.

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.