Session Function _php Tutorial

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

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