Php -- session control, php session

Source: Internet
Author: User
Tags php session

Php -- session control, php session
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 ();

 

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.