PHP Setcookie function invalidation

Source: Internet
Author: User
Recently in a Web site to write PHP background to find Setcookie This function is always unable to set the cookie normally, through Var_dump () found that the function return value is False, is clearly set unsuccessful, Google, found that Setcookie failure may have some reasons:

1. Cookies are disabled by the browser. Without checking, I'm certainly not disabled.

2. Using PHP's Setcookie () to create a cookie is the same as the Session_Start () that opens the session in PHP, and cannot have any HTTP header output before Setcookie (). I went to check the code and found the following code

Var_dump ($qOpenId); Setcookie (' Qopenid ', $openid, Time () + 30 * 24 * 3600, '/');

Decisive comment Var_dump ($OpenId) This line, test, success.

Personally, Setcookie should be directly set the contents of the HTTP header, so the front can not have any head output, Var_dump,echo anything can not have

Related articles:

Setcookie do not set the expiry time, set the path how to write?

PHP Setcookie Usage

Cookies set PHP Setcookie settings cookie usage and settings invalid problem

  • 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.