Session full Tutorial (iii) _php tutorial

Source: Internet
Author: User
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 ...

  • 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.