The role of the session is many, the most used is the site within the variable transfer of the page. At the beginning of the page we want to session_start (); open session;
Then you can use the SESSION variable, for example to assign a value is: $_session[' item ']= "Item1", to get the value is $item1=$_session[' item '; Here we may use some functions, such as determining if a SESSION variable is empty, so write: Empty ($_session[' Inum ') returns TRUE or false.
Let's take a look at a login procedure to determine if the username and password are correct.
The login form is like this: login.php
Processing files is like this
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 "";
}
}
Else
{
echo "";
}
}
Else
{
echo "";
}
?>
Conn.php is like this:
$conn =mysql_connect ("127.0.0.1", "", "" ");
mysql_select_db ("Shop");
?>
Since $_session[' AdminName ']= $username; we can write the file that verifies whether the login statement: checkadmin.asp
Session_Start ();
if ($_session[' adminname ']== ')
{
echo "";
}
?>
http://www.bkjia.com/PHPjc/760822.html www.bkjia.com true http://www.bkjia.com/PHPjc/760822.html techarticle the role of the session is many, the most used is the site within the variable transfer of the page. At the beginning of the page we want to session_start (), open the session, then we can use the session variable, for example ...