the address on the address bar don't change

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
jaylin
Forum Commoner
Posts: 68
Joined: Fri Nov 18, 2005 4:44 am

the address on the address bar don't change

Post by jaylin »

when i use

Code: Select all

header("Location: daily.php");
although the page is daily.php, the address in the address bar doesn't change and still "product.php". how can i fix it?

regard,
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Re: the address on the address bar don't change

Post by foobar »

jaylin wrote:when i use

Code: Select all

header("Location: daily.php");
although the page is daily.php, the address in the address bar doesn't change and still "product.php". how can i fix it?

regard,
There is no way of doing this with PHP. You'd have to use client-side redirecting using one of the following:

Code: Select all

<meta http-equiv="refresh" value="0; http://example.com/" />
...or...

Code: Select all

<script type="text/javascript">
top.location = 'http://example.com/';
</script>
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: the address on the address bar don't change

Post by Weirdan »

jaylin wrote:when i use

Code: Select all

header("Location: daily.php");
although the page is daily.php, the address in the address bar doesn't change and still "product.php". how can i fix it?

regard,
According to rfc2616 (HTTP protocol) responses with the status code of 302 (Found) mean:
rfc2616 wrote: 10.3.3 302 Found

The requested resource resides temporarily under a different URI. Since the redirection might be altered on occasion, the client SHOULD continue to use the Request-URI for future requests.
That's why user agent (browser) is free to leave old URI in address bar.

You may try to send 'HTTP/1.1 303 See Other' status line using:

Code: Select all

header('HTTP/1.1 303 See Other');
to indicate that
rfc2616 wrote: The response to the request can be found under a different URI and SHOULD be retrieved using a GET method on that resource.
though I doubt many browsers would follow the standard that scrupulously
AGISB
Forum Contributor
Posts: 422
Joined: Fri Jul 09, 2004 1:23 am

Post by AGISB »

1. Try using the complete URL like http://www.mysite.com/daily.php in the Location statement. This should do the trick as it generates a different response from the server

2. use exit() after the header command. I do and it always works nicely although I think that might not be the problem.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

AGISB wrote: 2. use exit() after the header command. I do and it always works nicely although I think that might not be the problem.
using die or exit after a header will just automatically send the header, if you don't then the page will execute, doing whatever sql queries there are then it will redirect. example:

Code: Select all

header("location: http://www.google.com");
header("location: http://www.yahoo.com");
die();
this will send you to yahoo instead of google. that is why it is always a very wise idea to die() or exit() right after you do a redirect header.
Post Reply