I recently upgraded from php 5.3 to php 5.6
But I received an error in my code:
Warning: Cannot modify header information - headers already sent by (index.php:1) in core.php on line 2927
LINE 2927
setcookie(COOKIE_TOKEN, NULL, -1);
COOKIE_TOKEN is:
define('COOKIE_TOKEN', 'name');
Warning: Cannot modify header information - headers already sent
The issue is caused by $HTTP_RAW_POST_DATA
: http://php.net/manual/en/migration56.deprecated.php
There's an example at the bottom that should help to confirm it:
<?php
ini_set('always_populate_raw_post_data',-1);
$HTTP_RAW_POST_DATA = file_get_contents('php://input');
echo $HTTP_RAW_POST_DATA;
?>
http://php.net/manual/en/reserved.variables.httprawpostdata.php
PHP 5.6 deprecated automatically populating the HTTP_RAW_POST_DATA variable and introduced a deprecation notice. If the setting is left at the default value of 0 requests in the core can trigger this notice although HTTP_RAW_POST_DATA isn't being used or accessed.
See also: Warning about `$HTTP_RAW_POST_DATA` being deprecated
The warning is clear.
Warning: Cannot modify header information - headers already sent by (index.php:1) in core.php on line 2927
From http://php.net/setcookie :
setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including and tags as well as any whitespace.
Move that setcookie statement before any HTML
appears:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.