<? PHP
Ob_start (); setcookie ("username", "bin", time () + 3600); echo "the username is :". $ http_cookie_vars ["username"]. "\ n"; echo "the username is :". $ _ cookie ["username"]. "\ n"; print_r ($ _ cookie);?> Warning: cannot modify header information-headers already sent by error cause in PHP Program Header ("cache-control: No-cache, must-revalidate"); then the page displays the above error, and N pieces of data have no results. Today, I occasionally found a problem with the configuration in my PHP. ini. In c: \ windows \, find the php. ini file output_buffering, which is off by default. Now I can set it to 4096. The error message is used to solve the Display Error and cannot be followed by (date + number of Exported Files) as the file name. the setcookie function must first send the preceding restrictions before any information is sent to the browser. Therefore, when setting the setcookie () function, "undefined Index" and "cannot modify header information-headers already sent "... To solve this problem, the method of "cannot modify header information-headers already sent by" is before the cookie is generated, extend the token to the receiver. Therefore, you can add ob_start (); at the beginning of the program. The ob_start () function is used to open the buffer. For example, if there is output before the header () function, including carriage return, space, line feed, and "header had all ready send by" errors, in this case, you can first use ob_start () to open the buffer PHPCode Both the data block and echo () output will enter the buffer and will not be output immediately. Of course, opening the buffer will play a lot of roles, as long as you play your imagination. You can summarize the following four points:
1. used before header ()
Ob_start (); // open the buffer echo \ "hellon \"; // output
Header ("Location: index. php"); // redirects the browser to index. php.
Ob_end_flush (); // output all content to the browser?>
2. the phpinfo () function can obtain client and server information, but the best method is to save client information using a buffer. ob_start (); // open the buffer phpinfo (); // use the phpinfo function $ info = ob_get_contents (); // obtain the buffer content and assign it to $ info $ file = fopen (\ 'info.txt \ ', \ 'W \'); // open the info.txt file.
Fwrite ($ file, $ info); // write the information to info.txt fclose ($ file); // close the info.txt file.
?>
3. Static Page Technology ob_start (); // open the buffer?> All PHP page output
$ Content = ob_get_contents (); // get all the content output on the PHP page $ fp = fopen ("output00001.html", "W"); // create a file and open it, prepare to write fwrite ($ FP, $ content); // write the content of the PHP page to output1_1.html, and then ...... Fclose ($ FP);?>
4. Output code function run_code ($ code) {if ($ code ){
Ob_start (); EVAL ($ Code); $ contents = ob_get_contents ();
Ob_end_clean ();} else {echo "error! No output "; exit ();} return $ contents ;}
ob_start (); setcookie ("username", "bin", time () + 3600); echo "the username is :". $ http_cookie_vars ["username"]. "\ n"; echo "the username is :". $ _ cookie ["username"]. "\ n"; print_r ($ _ cookie);?> Warning: cannot modify header information-headers already sent by error cause I added the header in the PHP program, header ("cache-control: No-cache, must-revalidate "); the above error is displayed on the page, and N documents are not returned. Today, I occasionally found a problem with the configuration in my PHP. ini. In c: \ windows \, find the php. ini file output_buffering, which is off by default. Now I can set it to 4096. The error message is used to solve the Display Error and cannot be followed by (date + number of Exported Files) as the file name. the setcookie function must first send the preceding restrictions before any information is sent to the browser. Therefore, when setting the setcookie () function, "undefined Index" and "cannot modify header information-headers already sent "... To solve this problem, the method of "cannot modify header information-headers already sent by" is before the cookie is generated, extend the token to the receiver. Therefore, you can add ob_start (); at the beginning of the program. The ob_start () function is used to open the buffer. For example, if there is output before the header () function, including carriage return, space, line feed, and "header had all ready send by" errors, in this case, you can use ob_start () to open the data block of the PHP code in the buffer zone and echo () to output the data in the buffer zone rather than immediately. of course, opening a buffer has a lot to do, as long as you can make full use of your imagination. you can summarize the following four points:
1. used before header ()
Ob_start (); // open the buffer echo \ "hellon \"; // output
Header ("Location: index. php"); // redirects the browser to index. php.
Ob_end_flush (); // output all content to the browser?>
2. the phpinfo () function can obtain client and server information, but the best method is to save client information using a buffer. ob_start (); // open the buffer phpinfo (); // use the phpinfo function $ info = ob_get_contents (); // obtain the buffer content and assign it to $ info $ file = fopen (\ 'info.txt \ ', \ 'W \'); // open the info.txt file.
Fwrite ($ file, $ info); // write the information to info.txt fclose ($ file); // close the info.txt file.
?>
3. Static Page Technology ob_start (); // open the buffer?> All PHP page output
$ Content = ob_get_contents (); // get all the content output on the PHP page $ fp = fopen ("output00001.html", "W"); // create a file and open it, prepare to write fwrite ($ FP, $ content); // write the content of the PHP page to output1_1.html, and then ...... Fclose ($ FP);?>
4. output code function run_code ($ code) {if ($ code) {
ob_start (); EVAL ($ Code); $ contents = ob_get_contents ();
ob_end_clean ();} else {echo "error! No output "; exit () ;}return $ contents ;}