Page 1 of 1

the address on the address bar don't change

Posted: Wed Nov 30, 2005 3:05 am
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,

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

Posted: Wed Nov 30, 2005 4:01 am
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>

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

Posted: Wed Nov 30, 2005 4:55 am
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

Posted: Wed Nov 30, 2005 7:48 am
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.

Posted: Wed Nov 30, 2005 8:20 am
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.