The difference between the header setting cookie and the built-in Setcookie in PHP

Source: Internet
Author: User
Tags set cookie setcookie

First of all, the browsing of the cookie operation is through the HTTP header (commonly known as "HTTP Header") to achieve. All cookie data transfer between server and client is done via HTTP request header.

PHP Setcookie (The implementation of the function) is to encapsulate the HTTP header, which seems to use the header and the use of Setcookie is the same.

Because header information belongs to the HTTP protocol content, you must first send the head information to the server, and then perform other operations such as data download, so there can be no content output before Setcookie and header (for example: echo/printf, etc.)

Header Set Cookie mode:

1 Header("Set-cookie:testcookie= Chinese; path=/; domain=.sunphp.org; Expires= ".Gmstrftime("%A,%d-%b-%y%h:%m:%s GMT",Time() +9600) ) ;

Setcookie Setup mode:
Syntax: Setcookie (name,value,expire,path,domain,secure)
Cases:

1 Setcookie("Website",' Www.sunphp.org ',Time()+3600*24) ;

Parameters Description
Name Necessary. Specifies the name of the cookie.
Value Necessary. Specifies the value of the cookie.
Expire Optional. Specify the validity period of the cookie.
Path Optional. Specifies the server path of the cookie.
Domain Optional. Specifies the domain name of the cookie.
Secure Optional. Specifies whether to transfer cookies through a secure HTTPS connection.

The difference between the header setting cookie and the built-in Setcookie in PHP

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.