The session variable in the php Tutorial is used to store information about user sessions or change the settings of user sessions. Session variables are stored by a single user and can be used on all pages of the application.
Php session variable
When you run an application, you open it, make some changes, and then close it. This is like a session. The computer knows who you are. It knows when to start the application and when to terminate it. However, there is a problem on the Internet: the server does not know who you are and what you are doing, because the http address cannot be maintained.
By storing user information on the server for subsequent use, php session solves this problem (such as user name and product purchase ). However, the session information is temporary and will be deleted after the user leaves the website. If you need to store information permanently, you can store the data in the database tutorial.
The session mechanism is to create a unique id (uid) for each visitor and store the variables based on the uid. The uid is stored in the cookie or transmitted through the url.
*/
Class my_session
{
Function my_session ()
{
// Destroy sessions started with session. auto_start
If (session_id ())
{
Session_unset ();
Session_destroy ();
}
Session_start ();
}
Function set ($ name, $ value)
{
$ _ Session [$ name] = $ value;
}
Function get ($ name)
{
If (isset ($ _ session [$ name])
Return $ _ session [$ name];
Else
Return false;
}
Function del ($ name)
{
Unset ($ _ session [$ name]);
}
Function destroy ()
{
$ _ Session = array ();
Session_destroy ();
}
}