Cookie and session (PHP for example)

Source: Internet
Author: User
Tags setcookie

Cookies

Setcookie function

Add a cookie

I. ($name, $value, $expire, $path, $domain);

II. $NAME: The name of the cookie

Iii. $value: The value of the cookie

Iv$expire: When the cookie expires, the cookie is automatically deleted

Delete Cookies

Let the cookie file expire

$path: There is a setting on the path, for example, set to the current path, meaning that the server only has the current path of the. php file to read the cookie

$domain: A valid domain name, which is valid only under that domain name (can be accessed)

There is no output before Setcookie in PHP (Echo)

Modify Cookies

Re-set Cookies

If the path is not given, then the current path is set, and if time is not given, the default browser is automatically destroyed when it is closed.

Querying cookies

Use $_cookie[cookie name]

Session

1. What is a session?

A) a conversational technique

b) A file stored in the server that holds the previously accessed information

c) The session query is based on the SessionID number

The principle of 2.Session

A) When the user first visits the server, the login information is stored in a session file on the server, and a SessionID number is generated, and a request is sent to the client browser to produce a cookie file. Store the SessionID number in the cookie, the second time the user came to visit the server, with a cookie with the SessionID number to access the server, the server according to the cookie SessionID number to find the corresponding session file,

c) The session query is based on the SessionID number

Operation of 3.Session:

A) Add sesion

b) Delete session

C) Modify session

d) Query session

Cookie and session (PHP for example)

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.