Jump to content


This topic is now archived and is closed to further replies.


Multiple header() calls in a row, possible?

Recommended Posts

I basically need to accomplish this feet:


header( "Location: page(random number).html );
wait 10 seconds

end repeat

Basically I want to write a script that iterates over and over again, changing the browser window to a different page each time. Sort of like an automatic 'tour' of a website. What method should I use to accomplish this? Can the PHP script still run even after the page header has changed?

This doesnt seem to work:

header( "Location: blah1.html );
sleep( 5 );
header( "Location: blah2.html );

As only blah2.html page loads. For some reason, even though blah1.html is told to load first, the code completely skips it and moves to blah2.html instead after 5 seconds.

Thanks in advance!

Share this post

Link to post
Share on other sites
You need javascript to do what you want the most effectively.

You can build an onload function that will wait 5 seconds before querying the server for another random page.

You really cannot do this with PHP. It is a server side script. All logic/functions done in PHP are executed on the server before it sends you the results.

For example, 'header()' is executed on the server. When the html hits your browser, the server is done executing your script.

hope that makes sense

Share this post

Link to post
Share on other sites
Something like this might work...instead of pointing to different html pages you could have it keep pointing to the php script and have the page refresh after 10 seconds. Use output buffering to prevent the typical header errors.




header("Location: /thisscript.php?page=$page");
header("Refresh: 10");


This is just off the top of my head...it may not work, or there may be a better solution. But it's an idea.

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.