In this article, you can learn how to use some of the basics of the session. After reading this article, perhaps you have learned the basic usage of the session!
PHP Session variables
When you run an application, you open it, make some changes, and then close it. It's like a conversation. The computer knows who you are. It knows when you start the application and when it terminates. But on the internet, there is a problem: the server does not know who you are and what you do, because the HTTP address does not maintain state.
By storing user information on the server for later use, the PHP session solves the problem (such as user name, purchase of goods, etc.). However, the session information is temporary and will be deleted when the user leaves the site. If you need to store information permanently, you can store the data in a database.
The Session works by creating a unique ID (UID) for each visitor and storing the variables based on this UID. The UID is stored in a cookie or transmitted via a URL (PS. In most cases we use cookies to save).
Start PHP Session
When a PHP page is running, the default session is not started and we need to start it manually. This is easy because you only need to call the following function!
Session_Start ()
But this will be called when the HTML code is not started, which is worth noting! Otherwise the error will be reported! Some students are very strange, why they clearly saved a value in the session, to another page will disappear! It is possible that the function is not called session_start ().
Store Session Variables
The SESSION in PHP is easy to use, but it is an array variable $_session. You can use the following statements to store session variables
$_session[' username ']= ' www.zeroplace.cn ';
You can also use or modify this variable at any time on any other page!
End Session
If we store the user's basic information in the session when the user logs in, we may want to destroy the session when the user exits.
unset ($_session[' username ');
Even, you can call the following function to clear all session variables.
Session_destroy ();
0th Space All rights reserved
http://www.bkjia.com/PHPjc/478260.html www.bkjia.com true http://www.bkjia.com/PHPjc/478260.html techarticle in this article, you can learn how to use some of the basics of the session. After reading this article, perhaps you have learned the basic usage of the session! PHP Session variable When you run a should ...