Third, the session application example
The following example snippets are for reference only, you can customize or you can not customize the session, as you
(1) for user authentication
Session_Start ();
$DBH =mysql_connect ("localhost:3306", "xxxx", "xxxx");
mysql_select_db ("Znsoft");//Select Database
$query = "selectuseridfromreguserwhereuserid= ' $userid ' andpass= ' $pass '";
$userid $pass is the user name and password passed in from the login form.
$res =mysql_query ($query, $DBH);
if ($row =mysql_fetch ($res))
{
$reguser = $row [0];
?>
}
Else
{
$reguser = "";
?>
You put the code on your own.
}
Session_register ("Reguser");
?>
Check whether you are logged in on another page
================
Session_Start ();
if (Isset ($reguser) && $reguser! = "")//already logged in
{
echo "Welcome, man";
}
else//not logged in!
echo "Please register";
?>
Exit function
===============================
Session_destroy ();
or $reguser= "";
?>
(2) for passing variables
This program is used to pass variables between pages
$name = "M.y";
if (!sesion_is_registered ("name"))//not register session variable name
Session_register ("name");//Register variable name
?>
Second page
===================
Echo$name;
Don't want to use it, delete it.
if (session_is_registered ("name"))//whether registered, if already registered
Session_unregister ("name");//Of course it's deleted.
?>
http://www.bkjia.com/PHPjc/629566.html www.bkjia.com true http://www.bkjia.com/PHPjc/629566.html techarticle Third, the session application examples of the following examples are for reference, you can customize or do not customize the session, as you will (1) for user authentication? Session_Start (); $dbh =mysql_connect (Localh ...