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.