PHP Development Session principle and the use of detailed

Source: Internet
Author: User
Tags php session

Store a user's information, change the user session settings, all pages can be used. This article is mainly to share with you the PHP development session principle and the use of detailed, hope to help everyone.

PHP Session variables

Open the program, make some changes, and then save the exit. is a session. The server can know who is operating through the session.
Working mechanism: Create a UID for the visitor, depending on the UID store variable, the UID is stored in a cookie, or URL conduction.

Using the PHP Session

Store user information before session, initiate a reply
Note: the Session_Start () function must precede the label:

<?php session_start ();  ? >

Register user sessions with the server to save user information while assigning a UID to a user session

Store Session variables

Storing and retrieving sessions is used$_SESSION

<?phpsession_start ()///Store session data if (Isset ($_session[' views '))} {    $_session[' views ']=$_session[' views ']+ 1;} else{    $_session[' views ']=9999;}? >

Output "Views: 9999"

Destroy Session

Which or function to use to unset() session_destroy() destroy

<?phpsession_start (); if (Isset ($_session[' views ')) {    //releases the specified SESSION variable    unset ($_session[' views ');} Complete destruction of Sessionsession_destroy ();? >

Function: Store a user's information, change the user session settings, all pages can be used.

PHP Session variables

Open the program, make some changes, and then save the exit. is a session. The server can know who is operating through the session.
Working mechanism: Create a UID for the visitor, depending on the UID store variable, the UID is stored in a cookie, or URL conduction.

Using the PHP Session

Store user information before session, initiate a reply
Note: the Session_Start () function must precede the label:

<?php session_start ();  ? >

Register user sessions with the server to save user information while assigning a UID to a user session

Store Session variables

Storing and retrieving sessions is used$_SESSION

<?phpsession_start ()///Store session data if (Isset ($_session[' views '))} {    $_session[' views ']=$_session[' views ']+ 1;} else{    $_session[' views ']=9999;}? >

Output "Views: 9999"

Destroy Session

Which or function to use to unset() session_destroy() destroy

<?phpsession_start (); if (Isset ($_session[' views ')) {//releases the specified SESSION variable unset ($_session[' views ');} Complete destruction of Sessionsession_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.