Talking about user authentication of PHP (IV.)

Source: Internet
Author: User
Talking about user authentication of PHP (IV.)
Popcorn 2001 12,28 Www.westxj.net
Hello everyone, the previous section of this paper is based on the HTTP Single-user and multiuser password Authentication procedures, this method for the need for authentication pages, is the best. However, this validation cannot be used in PHP under the Php,iis of CGI mode. Therefore, we can use the session in different pages to save user information, to achieve the purpose of verification.
Session refers to the time interval between a terminal user communicating with an interactive system, usually the time elapsed between registering into the system and logging off from the system. The session function is the way it defines global variables through PHP scripts, making the global variable valid for all PHP scripts in the same session.
The following is a user login form handler:
?
$db =mysql_connect ("localhost", "root", "1234");
Connecting to a database server
mysql_select_db ("Jane", $db);
Connecting to a database
$result =mysql_query ("select * from user where name= ' $name ' and password= ' $pass '", $db);
Send query is string to database
if ($myrow = Mysql_fetch_row ($result))
If the record pointer is True
{
Session_Start (); Session initialization
Session_register ("user"),//Register user variable
$user = $myrow ["User"];
echo "Verify success!"
}
Else
{
echo "Authentication failed!";
}
?>
Add the following program to the beginning of the page you want to protect:
?
Session_Start ();
if (!session_is_registered ("user"))//Check that the session variable is registered
{
echo "validation failed, illegal login!";
}
Else
{
......

}
?>



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.