Jump to content


Photo

Multiple header() calls in a row, possible?


  • Please log in to reply
2 replies to this topic

#1 qwave

qwave
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 25 June 2006 - 01:48 AM

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!

#2 jajtiii

jajtiii
  • Members
  • PipPipPip
  • Advanced Member
  • 43 posts

Posted 25 June 2006 - 02:55 AM

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

#3 robos99

robos99
  • Members
  • PipPipPip
  • Advanced Member
  • 55 posts

Posted 25 June 2006 - 03:03 AM

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.

ob_start();

$page=rand();

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

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

ob_end_flush();

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users