Session in PHP creates a print release destroy;

Source: Internet
Author: User
Tags change settings php session

PhpSession

The PHP session variable is used to store information about user sessions (session) or to change settings for user sessions. The Session variable stores information for a single user and is available for all pages in the application.

PHP Session variables

When you manipulate an application on your computer, you open it, make some changes, and then close it. It's much like a conversation (session). The computer knows who you are. It knows when you open and close the application. However, the problem arises on the Internet: the WEB server does not know who you are and what you have done because the HTTP address cannot remain in the state.

The PHP session solves this problem by storing user information on the server for subsequent use (e.g., 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 through a URL.

1<?PHP2 Session_Start();//Opening Session Sessions3 if(isset($_session[' views '])) {//Use the Isset function to determine if a cookie exists,4     $_session[' Views ']=$_session[' Views ']+1;//the original value of the cookie is +15}Else{6     $_session[' Views ']=1;//Assign 1 to $_session[' views ';7 }8 Echo"Browse Volume:".$_session[' views '];//output Native-stored session9 unset($_session[' views ']);//Releasing session VariablesTen Session_destroy();//destroy, kill the session . One?> A<meta charset= "Utf-8"/>

The Session_Start function must precede the HTML tag;

Session in PHP creates a print release 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.