Chapter 4 session control

Source: Internet
Author: User
Tags set cookie

 

Learning points:
1. Cookie Application
2. Session Processing

 

HTTP (Hypertext Transfer Protocol) defines the transmission of text, graphics, video and all
All other data rules. HTTP is a stateless protocol, indicating that each request is processed with the previous or subsequent
The request is independent. Although this simplification has made outstanding contributions to the popularization of HTTP
For Web application developers, this is a bit of a problem. To solve this problem
A small amount of information (cookies) is stored on the machine ).
Due to cookie size restrictions, quantity, and other reasons, developers propose another solution: session
Processing.

 

1. Cookie Application

Set cookie:Setcookie() Function can generate a cookie file on the client, which can be saved
Time, name, value, and so on.


Create cookie

<?('name','Lee',()+(7*24*60*60?>

Parameter 1: cookie name
Parameter 2: cookie value
Parameter 3: cookie expiration time

 

Read cookie

<? ['name'?>

 

Delete cookie

<?('name',''('name','Lee',()-1?>

 

Cookie usage restrictions

1. It must be set before HTML file content output;
2. Different browsers may encounter inconsistent processing of cookies and sometimes incorrect results.
3. restrictions are imposed on the client. A browser can create up to 30 cookies, and each Cookie cannot
More than 4 kb, each WEB site can set a total of 20 cookies.

 

Ii. Session Processing

When session processing is used, you must start the session and start the session with session_start.

Create a session and read the session

<?['name'] = 'Lee' ['name'?>

Determine whether a session exists

<?['name'] = 'Lee' ((['name' ['name'?>

Delete session

<?['name'] = 'Lee'(['name' ['name'?>

Destroy all sessions

<?['name'] = 'Lee'['name2'] = 'Lee' ['name' ['name2'?>

Note: This article is a video tutorial from Li Yanhui PHP. This article is intended for communication purposes only and cannot be used for commercial purposes. Otherwise, the consequences will be borne by you.

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.