Session Tracking Technology--session

Source: Internet
Author: User

First, what is the session
    • The session begins with the user access page, to the point where the connection to the site is disconnected, forming the life cycle of a conversation. During a session, the client is assigned a unique SessionID that identifies the current user and distinguishes it from other users.
    • Session, SessionID will be stored on both the client and server side two locations, for the client to use a temporary cookie to save (cookie name is called PHPSESSID) or through a URL string passed, The server side is also saved as a text file in the specified session directory.
    • The session receives each access request through the ID, thus identifying the current user, tracking and maintaining the user's specific data, and session variables (which can be stored in the session during the session for digital or textual data), such as session_name, etc. These variable information is stored on the server side.
    • SessionID can be saved as session information in the database, and the session can be persisted, so as to track each user's login times, online or not, online time, etc.
Second, the basic steps to use the session:
    • Start session
      • session_start () starts a session or returns a session that already exists.
    • Registering Session Variables
      • PHP5 uses $_session[' xxx ']=xxx to register the SESSION global variable. It is similar to the Get,post,cookie method.
      • Example:
        $_session [' username ']= "Tangcaiye";
    • Using Session Variables
      • Example:
        Echo $_session [' username '];
    • Unregister variables and destroy sessions
      • Logout Example:
        • Example:
          Session_Start (); unset ($_session[' username ']);
      • To destroy a session:
        • The Session_unset () function clears all variables stored in the current session, which effectively resets the session to the state it was created in.
        • The Session_destroy () function completely removes the session from the storage mechanism, invalidating the current session.
Third, the difference between the cookie and session:
    • Both cookies and sessions can temporarily hold variables used in multiple pages, but they differ in nature:
    • Cookies are stored in the client browser;
    • Session is saved on the server;
    • The link between them is that the session ID is usually stored in a cookie or placed on a URL.

Session Tracking Technology--session

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.