Php session processing

Source: Internet
Author: User
Tags php session php tutorial sessions unique id

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 ();
 }
 
}

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.