Wednesday, August 28, 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

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...