Php -- Session Control

Source: Internet
Author: User
: This article mainly introduces php-Session Control. if you are interested in the PHP Tutorial, you can refer to it. 1. what is session control?

Allows the server to make consecutive requests based on the client.

2. Why is session control required?

Because when you open a website and want to access other pages of the website, if there is no session control, you need to enter your account and password again when you jump to other pages.

3. Principles and functions of cookies

Save the simple information of the client in the personal PC. Other programs obtain the Cookie of the PC to obtain the user's information. In this way, you do not need to enter your account and password.

Note: setCookie () must be used before php outputs the first sentence; otherwise, it is invalid.

4. how to use Cooike (general)

Create Cookie

SetCookie ("key", "value", retainTime); // Create a Cookie

Call Cookie

If ($ _ COOKIE ["key"] = "admin") {// Cookie is the super array echo provided by php "data retrieved ";}

Delete Cookie

// The first method setCookie ("key"); // you only need to enter the key name. // The second method setCookie ("key", "", time () -1000); // Make the retention time less than the current time

Cookie can be changed to a multi-dimensional array

SetCookie ("user [key]", "values"); // equivalent to $ _ COOKIE ["user"] ["key"]


Simple example: Cookie-based user login

5. Principles and functions of sessions

Store information on the server rather than on a personal PC.

6. how to use Session

(1). configure the php. ini option (do not expand, and query relevant documents by yourself)

(2). start the session

Session_start (); // you must call this method before using session.

Purpose: load Session-related built-in environment variables into the memory in advance.

(3) Call

$ _ SESSION ["key"] = "value"; // $ _ SESSION is also a super array and called as an array

(4) Delete

// Delete a single unset ($ _ SESSION ["key"]); // delete all $ _ SESSION = array (); // Set it to an empty array // delete session_destory () from the Session file corresponding to the user on the server ();

The above introduces php-session control, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

Related Article

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.