PHP header location time?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

PHP header location time?

Post by JAB Creations »

I know I've seen it somewhere, setting how long PHP should wait until it executes the following code...

Code: Select all

header ("Location: http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: PHP header location time?

Post by Zoxive »

JAB Creations wrote:I know I've seen it somewhere, setting how long PHP should wait until it executes the following code...

Code: Select all

header ("Location: http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
If you sleep() server side the page will be blank with nothing.

If you want to show html you will need a meta redirect. (Which is client side)
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: PHP header location time?

Post by JAB Creations »

If it isn't related to header location then it's :offtopic:

http://us3.php.net/header
I know it's directly related to location but it's not documented on php.net!
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: PHP header location time?

Post by JAB Creations »

It looks sort of like this though this isn't waiting the ten seconds...

Code: Select all

header ("Location: http://localhost/", 10);
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: PHP header location time?

Post by RobertGonzalez »

Have you tried:

Code: Select all

<?php
// 5 second refresh rate
header('Refresh: 5; url=http://' . $_SERVER['HTTP_HOST'] . basename(__FILE__));
exit;
?>
Don't know if it will work but it is worth a shot.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: PHP header location time?

Post by JAB Creations »

It works but it's not the answer to my question.

Code: Select all

header("refresh: 5; url='http://localhost/'");
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: PHP header location time?

Post by Zoxive »

JAB Creations wrote:It works but it's not the answer to my question.
I don't see a question. Other then the original post name, which seems to have been answered.
Last edited by Zoxive on Mon Mar 17, 2008 9:46 pm, edited 1 time in total.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: PHP header location time?

Post by JAB Creations »

A header location with a time set in seconds before the page redirects. The browser obviously receives the commend via headers and does not redirect the page for X number of seconds.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: PHP header location time?

Post by Zoxive »

JAB Creations wrote:A header location with a time set in seconds before the page redirects. The browser obviously receives the commend via headers and does not redirect the page for X number of seconds.
Read my first post, and/or give us an example of a website which already does this.

How does it obviously get it via headers? If there is a delay there has to be something sent, and then a wait. This is done on the forum here, when you post messages via meta-refresh.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: PHP header location time?

Post by JAB Creations »

All I know is that it looks something like this...

Code: Select all

header ("Location: http://localhost/", 10);
I've used it myself and it's very minimal code.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: PHP header location time?

Post by RobertGonzalez »

Are you sure you were using a native PHP function?
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: PHP header location time?

Post by JAB Creations »

I don't recall where I got it from but the code looked like that. I used Advanced Find & Replace to look through all the files in my web folder to see if I had a copy of it with the timer though I couldn't find it. I remember using it though at one point.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: PHP header location time?

Post by RobertGonzalez »

I was only asking because the behavior of the header() function does not work the way your example works. If the syntax is as you say it was then I would guess that there was another function taking the params and doing something with them.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP header location time?

Post by Christopher »

Sounds more like the "meta-equiv" tag that goes in <head> to me. That has a time with it.
(#10850)
Post Reply