Summary of cookies and Sessions

Source: Internet
Author: User
: This article mainly introduces the summary of cookies and Sessions. For more information about PHP tutorials, see.
Cookie Session
Storage location
Stored in a browser

Real files exist on the server

, K exists in the browser

Security
Low, easy to forge Higher than cookie security
Set
Setcookie () function

Session_start ()

Function operations

Storage type
Scalar type: int, float, char, bool, null All types except resources
Lifecycle

Set through the third parameter

For example, setcookie ('school ', 'xtu', time () + 15 );

Use the php. ini file to set

Session. cookie_lifetime

Session. gc_maxlifetime

Valid Path

Set through the fourth parameter

Setcookie ('school ', 'kefeng', time () + 5 ,'/');

Depends on the valid cookie path

Php. ini can be configured as follows:

Session. cookie_path =/

Valid domain name

Set through the fifth parameter

String'Www .example.com'

Depends on the valid domain name of the cookie

Php. ini can be configured as follows:

Session. cookie_domain =

Read
$ _ COOKIE [''] $ _ SESSION ['']
Destroy

Setcookie (",", 0)

Setcookie (",", time ()-1)

Four destruction methods:

1. destroy a unit:

Unset ($ _ session ['school']);

2. Overall cleanup:

$ _ Session = array ();

3. clear all functions:

Session_unset ();

4. no boxes are needed:

Session_destory ()

Principle

Between browsers and servers

Server load balancer

Data transmission through HTTP headers

Next intercommunication with the browser

Carry the HTTP header to the server

Store K in this process

(Number of browsers to servers

Data interaction) V is stored on the server

In the process

The data for server interaction is K.


The above section describes the summary of cookies and sessions, including related content, and hopes to help those who are interested in PHP tutorials.

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.