Session full tutorial (III ). III. session application examples the following sample pieces are for reference only. you can customize or not customize the session as needed (1) for user authentication? Session_start (); $ dbhMySQL_connect (localh 3. session application example
The following examples are for reference only. you can customize or not customize the session.
(1) used for user authentication
Session_start ();
$ Dbh = MySQL_connect ("localhost: 3306", "xxxx", "xxxx ");
MySQL_select_db ("znsoft"); // select a database
$ Query = "selectuseridfromreguserwhereuserid = '$ userid' andpass =' $ pass '";
// $ Userid $ pass is the user name and password passed by the login form
$ Res = MySQL_query ($ query, $ dbh );
If ($ row = MySQL_fetch ($ res ))
{
$ Reguser = $ row [0];
?>
Script
Alert ("OK, buddy, welcome! ");
Script
}
Else
{
$ Reguser = "";
?>
Script
Alert ("sorry, you are not a registered user! ");
Script
// Put the code on your own
}
Session_register ("reguser ");
?>
Check whether you have logged on to the other page
======================
Session_start ();
If (isset ($ reguser) & $ reguser! = "") // You have logged on
{
Echo "Welcome, buddy ";
}
Else // no logon
Echo "register now ";
?>
Exit
====================================
Session_destroy ();
// Or $ reguser = "";
?>
(2) used to pass variables
This program is used to pass variables between pages
$ Name = "m. y ";
If (! Sesion_is_registered ("name") // The session variable name is not registered.
Session_register ("name"); // register the variable name
?>
Page 2
==============================
Echo $ name;
// You don't want to use it anymore. delete it.
If (session_is_registered ("name") // whether to register, if you have already registered
Session_unregister ("name"); // delete It of course
?>
The following examples are for your reference only. you can customize or not customize the session, as you can (1) for user authentication? Session_start (); $ dbh = MySQL_connect (localh...