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. Here we can learn how to use 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.