Php logon and logout instance code _ PHP Tutorial

Source: Internet
Author: User
Php logon and logout instance code. Pm_user is a data table that has not been created. you can create a table on your own. The following describes only the program code for logging on with php and then logging out, for more information, see pm_user. we have not created a table in the data table. you can create a table on your own. next we will only introduce the program code for logging on with php and then logging out, if you need it, you can refer to it.

Login.htm

The code is as follows:





Untitled Document





Login. php

The code is as follows:

Function showPage () // determine whether to log on without logon. directly jump to the logon page.
{
If (! Isset ($ _ SESSION ["user"]) &! Isset ($ _ SESSION ["pwd"])
{
If (isset ($ _ COOKIE ["user"]) & isset ($ _ COOKIE ["pwd"])
{
$ SQL = "select * from pm_user where u_user = '$ _ COOKIE [user]'";
$ Query = mysql_query ($ SQL );
$ IsUser = is_array ($ row = mysql_fetch_array ($ query); // judge the user name
$ IsPwd = $ isUser? $ Row ["u_pwd"] === _ COOKIE ["pwd"]: false; // Determine the password
If ($ isPwd)
{
$ _ SESSION ["user"] = $ _ COOKIE ["user"];
$ _ SESSION ["pwd"] = $ _ COOKIE ["pwd"];
$ _ SESSION ["id"] = $ _ COOKIE ["id"];
$ _ SESSION ["name"] = $ _ COOKIE ["name"];
}
}
}

If (! Isset ($ _ SESSION ["user"]) &! Isset ($ _ SESSION ["pwd"])
{
Echo 'script alert ("You haven't logged on! Returning to the login page... "); location. href =" index. php "; script ';
Exit ();
}
}

Log out

Out. php

The code is as follows:

Function loginOut () // logout function
{
If (isset ($ _ GET ["login"]) = 'out ')
{
$ _ SESSION ["user"] = '';
$ _ SESSION ["pwd"] = '';
$ _ SESSION ["id"] = '';
$ _ SESSION ["name"] = '';
Session_destroy ();
Echo 'script alert ("exited successfully! "); Location. href =" index. php "; script ';
}
}

...

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.