Why the cookie failed to set

Source: Internet
Author: User
Why does a cookie fail to set?
I have a program like this:
if (Setcookie (' Me ', ' MyCookie '))
{
echo "Cookie has been set";
}
echo "Logged in";

The result of the run is "logged in" Yes, but "cookie is set" is not displayed. This indicates that the cookie setting failed.

May I ask why this section of the program is set to fail? Is there a grammatical error? What could be the cause of the failure? (My browser supports cookies)

Share to:


------Solution--------------------
Setcookie () defines a cookie that is sent along with the rest of the HTTP headers. Like other headers, a cookie must be sent before any other output from the script (this is a protocol restriction). This requires that the call to this function be placed before any output, including the label and any spaces. If there is any output before calling Setcookie (), this function will fail and return FALSE. Returns TRUE if the Setcookie () function runs successfully.

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