<?php
Ob_start ();
Setcookie ("username", "Test", Time () +3600);
echo "The username is:". $HTTP _cookie_vars["username"]. " \ n ";
echo "The username is:". $_cookie["username"]. " \ n ";
Print_r ($_cookie);
?>
Prompted Warning:cannot Modify header Information-headers already sent by error while accessing the PHP file
The reason is that the header of the PHP program has been added, headers ("content-type:text/html; Charset=utf-8 "); The above error appears on the page. On the Internet to check some information, that is my php.ini inside the configuration out of the problem, find the php.ini file output_buffering default is off, change it to on or any number, but try to have no results.
The Setcookie function must be sent out before any data is output to the browser.
Based on these limitations, when you execute the Setcookie () function, you often encounter "Undefined index", "Cannot modify header Information-headers already sent by" ... Cannot modify header information-headers already sent by "This is the wrong way to delay the data output to the browser before the cookie is generated, so you can add ob_ to the front of the program. Start () function.
The Ob_start () function is used to open the buffer, such as the header () function, if there is output, including carriage return \ space \ newline \ will have "Header had all ready to send by" error, you can first use Ob_start () The data Block and Echo () output that open the buffer PHP code will go into the buffer without immediately outputting:
The problem is resolved by the following methods:
Before the header ()
Ob_start (); Open buffer
echo \ "Hellon\"; Output
Header ("location:index.php"); redirect the browser to index.php
Ob_end_flush ();//output all content to the browser
?>
Php:cannot Modify header Information-headers already sent by error resolution