Introduction to php session management cookies

Source: Internet
Author: User
Tags php session
& Amp; lt ;? Phpif (! Isset ($ _ COOKIE ['visited']) {// if the cookie does not exist, create a new setcookie (& quot; visited & quot;, & quot; www. phpddt. co
 

The session management mechanism only includes the cookie and session mechanisms. let's talk about the cookie and session applications!
(1) Cookie is a small text file used to save user names, passwords, and personalized settings. when a user accesses a website,
A file like this will be generated and saved on the user's computer. Generally, the browser will store Cookies in their temporary files!
Note that Cookies do not store confidential information, such as bank accounts, in consideration of security issues!
The setcookie () function is used in php to generate a cookie. See the following simple example:


 
 

It can be seen that the setcookie () function mainly receives six parameters:
Name: cookie name (required)
Value: The cookie value.
Expires: cookie Expiration Time (required)
Path: "/" indicates that all arrays in this field can be accessed and read.
Domain: valid cookie domain name
Secure: bool value. if it is true, it indicates that the cookie can be sent to the client only when the ssl encrypted connection is established.
Note that no script can be output before the setcookie () function. Otherwise, an error is returned.
Let's take a look at the following complete example:

So how do we know about cookies?
A simple answer is to reference the principle of cookie name. set the expires (cookie expiration time) parameter of the setcookie () function to a value smaller than the current time!
For example:
Setcookie ("username", NULL, mktime-3600 ,"/");
?>

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.