Cookies set PHP Setcookie settings cookie usage and settings invalid problem

Source: Internet
Author: User
Tags setcookie
The result is a problem, Setcookie set the cookie does not take effect, not seen on the browser side. Check it out, it turns out that Setcookie is done by the header of the HTTP request response and needs to be executed before the output of the request response content (as with other header settings).
In the case of error_reporting = E_all in php.ini, the following prompts will be displayed after the output is Setcookie:

Warning:cannot Modify header Information–headers already sent by (output started at c:\xampp\htdocs\b.php:2) in ... on Li Ne ...

But because at that time php.ini set to error_reporting = E_all & ~e_notice, so there is no hint, so when the development is recommended to set error_reporting = E_all to facilitate the observation of some anomalies.
Attach a Setcookie usage instance
a.php

<?php Setcookie ("page", "a.php"); $page = $_cookie["page"]? $_cookie["page"]: "Unknown"; echo "from". $page. "<br/><br/>";?> this is a.php. Go to <a href= "b.php" >b.php</a>

b.php

<?php Setcookie ("page", "b.php"); $page = isset ($_cookie["page"])? $_cookie["page"]: "Unknown"; echo "from". $page. "<br/><br/>";?> this is b.php. Go to <a href= "a.php" >a.php</a>

The above describes the cookies set PHP Setcookie settings cookie usage and settings are invalid, including the content of the cookie settings, I hope that the PHP tutorial interested in a friend to help.

Related articles:

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

PHP Setcookie Usage

PHP Setcookie function invalidation

  • Related Article

    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.