php--Session Control

Source: Internet
Author: User
Tags setcookie

1. What is called session control

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

2. Why do I need session control?

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

The principle and function of 3.Cookie

Save the client's simple information on the personal PC, and other programs get the cookie from the PC to get the user's information. This will not require the user to enter their own account and password.

Note: Setcookie () must be used before the first sentence of PHP output, otherwise invalid

4. How to use Cooike (general)

Create a cookie

Setcookie ("Key", "value", retaintime); // Create a cookie

Invoke Cookie

if ($_cookie["key"] = = "Admin"//cookie is a  super array provided by PHP echo "Get data Success";       }

Delete Cookies

// The first of these methods Setcookie ("Key"); // just enter the key name///second method Setcookie ("Key", "",Time ()-1000); // make the retention time less than the current time

Cookie support becomes multidimensional array

Setcookie // equivalent to $_cookie["user" ["Key"]


Simple example: cookie-based user login

The principle and function of 5.Session

Store information on a server instead of on a personal PC.

6. How to use the session

(1). Configure the php.ini option (do not expand, query related documents yourself)

(2). Start session

Session_Start (); // The method must be called before the session can be used

Role: Pre-load the built-in environment variables associated with the session into memory.

(3) Call

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

(4) Delete

// Single Delete unset ($_session["Key"]); // Delete all $_session Array // set to an empty array//the user on the server side of the session file to delete session_destory ();

The above describes the php--session control, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.