Home  >  Article  >  Backend Development  >  Detailed explanation of the function of getting started with PHP session 3_PHP tutorial

Detailed explanation of the function of getting started with PHP session 3_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:39:58681browse

Session application examples
The following example fragments are for reference only. You can customize the session or not, as you like
(1) Used for user authentication
session_start();
$dbh=mysql_connect("localhost:3306","xxxx","xxxx");
mysql_select_db("znsoft");// Select database
$query="selectuseridfromreguserwhereuserid=$useridandpass=$ pass";
//$userid$pass is the username and password passed by the login form
$res=mysql_query($query,$dbh);
if($row=mysql_fetch($res)) < /script>
} else {
$reguser="";
?>
<script><br> alert("Sorry, you are not a registered user !");<br> </script>
}
session_register("reguser");
?>

Check whether you have logged in on another page
================
session_start();
if(isset ($ reguser) && $ reguser! = "") // Log in
{
echo "Welcome to you, buddy";
} else {// ";
    }
?>

Exit function
============================ ====
session_destroy();
//or $reguser="";
?>


(2) is used Pass variables
This program is used to pass variables between pages
                                                                                                                                                                              Variable name
session_register("name");//Register variable name
?>

Second page
=============== ====
                               echo $name;
session_unregister("name");//Delete it of course
?>





http://www.bkjia.com/PHPjc/486243.html

www.bkjia.com

true
http: //www.bkjia.com/PHPjc/486243.html

TechArticle

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn