Wednesday 28 August 2019

php - how to jump to other page after header had been sent?




how to jump to other page after header had been sent ?



I have some codes writed in my template file, I want to using php to jump to other page when some condition is true, but I can not use header command here ,for the header info had been sent in other php file before this template file. then how can I jump to other url now ? only the way to use js?



Warning: Cannot modify header information - headers already sent by ...

Answer



Use output buffering and header clearing to achieve this.




ob_start()
...
if (!headers_sent()) {
foreach (headers_list() as $header)
header_remove($header);
}
ob_flush_end()



Untested, but give it a shot.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...