Ten days to learn the seventh day of php _ PHP-php Tutorial

Source: Internet
Author: User
Objective: to learn how to use a SESSION has many functions. most of the functions are to pass variables between pages on the site. At the beginning of the page, we want to start session_start (); enable the SESSION; then we can use the SESSION variable. for example, to assign a value: $ _ SESSION [item] item1; the value to be obtained is $ item1 $ _ SESSION [item];, which is simple. Objective: to learn how to use a SESSION

SESSION has many functions, most of which are the variable transfer between pages on the site. At the beginning of the page, we want session_start (); to enable SESSION;
Then you can use the SESSION variable. for example, the value to be assigned is $ _ SESSION ['item'] = "item1 "; the value to be obtained is $ item1 = $ _ SESSION ['item'];, which is simple. Here we may use some functions. for example, to determine whether a SESSION variable is null, we can write: empty ($ _ SESSION ['inum']) and return true or false.

Next, let's take a look at the above description to check whether the user name and password are correct.
The login form is as follows: login. php






This is the case when processing files.
Require_once ('Conn. php ');
Session_start ();
$ Username = $ _ POST ['username'];
$ Password = $ _ POST ['password'];
$ Exec = "select * from admin where username = '". $ username ."'";
If ($ result = mysql_query ($ exec ))
{
If ($ rs = mysql_fetch_object ($ result ))
{
If ($ rs-> password = $ password)
{
$ _ SESSION ['adminname'] = $ username;
Header ("location: index. php ");
}
Else
{
Echo "script alert ('password Check Error! '); Location. href = 'login. php'; script ";
}
}
Else
{
Echo "script alert ('username Check Error! '); Location. href = 'login. php'; script ";
}
}
Else
{
Echo "script" alert ('database Connection Error! '); Location. href = 'login. php'; script ";
}

?>

Conn. php is like this:
$ Conn = mysql_connect ("127.0.0.1 ","","");
Mysql_select_db ("shop ");
?>

Because $ _ SESSION ['adminname'] = $ username; we can write a file to verify whether the statement is logged on: checkadmin. asp.
Session_start ();
If ($ _ SESSION ['adminname'] = '')
{
Echo "script" alert ('Please Login First '); location. href = 'login. php'; script ";
}
?>

Let's talk about how to create a page tomorrow.

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.