Jump to content

Multiple header() calls in a row, possible?


qwave

Recommended Posts

I basically need to accomplish this feet:


repeat

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!
Link to comment
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
Link to comment
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.

[code]
ob_start();

$page=rand();

include_once("htmlpage$_GET['page'].html");

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

ob_end_flush();
[/code]

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.