469,283 Members | 2,297 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,283 developers. It's quick & easy.

header redirection and adress bar

Hi,

I have a problem with redirection using the header function. The page
towards which I redirect loads correctly, but the url in the browser's
address bar is different is that of the redirecting page. Both pages are
located in different directories, so that my relative links don't work in
the page, because the browser retrieves the current directory from the wrong
url in the location bar.
This problem occurs only on the server of my webhosting provider, not on my
local machine where I can see the correct url after redirection. So I
assume, this is a server specific setting. But how can I change ist?

TIA,
Bernd
Jul 17 '05 #1
7 4556
"Bernd Liebermann" <12**@bernd-liebermann.de> wrote in message news:<c1**********@online.de>...
Hi,

I have a problem with redirection using the header function. The page
towards which I redirect loads correctly, but the url in the browser's
address bar is different is that of the redirecting page. Both pages are
located in different directories, so that my relative links don't work in
the page, because the browser retrieves the current directory from the wrong
url in the location bar.
This problem occurs only on the server of my webhosting provider, not on my
local machine where I can see the correct url after redirection. So I
assume, this is a server specific setting. But how can I change ist?


How are you redirecting the page? Can you post a code sample to look at?

/s/ WP
Jul 17 '05 #2
>
How are you redirecting the page? Can you post a code sample to look at?

/s/ WP


Sure.

if ($some_condition) {
header("location:/update/update1.php");
exit;
}

No characters sent to the page at that point.

As I said, update1.php is processed correctly, only that the url of the
redirecting page located in "/" stays in the address bar. So any relative
links in update1.php use "/" as basedir instead of "/update". I know that
there are workaraounds like clientside redirection or specifying <BASE>
information in the html header. But I would like to understand why this
causes problems on my whp's server and not my local pc.

Thanks for your interest.
Bernd
Jul 17 '05 #3
Bernd Liebermann wrote:
header("location:/update/update1.php");
That would be the proper way to engineer a redirect in PHP, save that
the Location field value does not consist of an absolute URI: an all-
too-common violation of RFC2616.
No characters sent to the page at that point.
Right. The redirect wouldn't happen otherwise.
As I said, update1.php is processed correctly, only that the url of the
redirecting page located in "/" stays in the address bar. So any relative
links in update1.php use "/" as basedir instead of "/update".
(ITYM "/update/", if I've interpreted "basedir" as what you'd
intended it to mean. It'd be better to express this "basedir" in
terms of an "absolute 'base URL'", using a dummy domain if you like.)

Any browser behaving like that is severely broken. There are three
ways to determine the base URL of an HTML document (HTML4.01, sec.
12.4.1); fetching the contents of the address bar is definitely *not*
one of them. What browser misbehaves this way?
I know that there are workaraounds like clientside redirection
You misspelt "nasty hacks". :-)
or specifying <BASE> information in the html header.
Using the BASE element is certainly a possibility, but it ought to be
unnecessary for any user-agent worth its salt. I'd rather get to the
root of the problem, and so would you:
But I would like to understand why this causes problems on my whp's server
and not my local pc.


Will you provide a URL of a document demonstrating this?

--
Jock
Jul 17 '05 #4
Will you provide a URL of a document demonstrating this?


http://ro.bernd-liebermann.de/login.php
http://ro.bernd-liebermann.de/login.php.txt (for php-source)

http-user: debug
http-pwd: debug

On login.php, enter "1" for user and "dick" as password. This script calls
itsself and redirects to /update/update1.php if login succesful. The problem
occurs with IE and Netscape.

Thanks for your help!
Bernd
Jul 17 '05 #5
Bernd Liebermann wrote:
http://ro.bernd-liebermann.de/login.php
http://ro.bernd-liebermann.de/login.php.txt (for php-source)

http-user: debug
http-pwd: debug

On login.php, enter "1" for user and "dick" as password. This script calls
itsself and redirects to /update/update1.php if login succesful. The problem
occurs with IE and Netscape.


Well, sorry, I've no idea. My browser doesn't even get redirected.
I'd suggest removing the unnecessary gunk until you figure out what
the problem is.

--
Jock
Jul 17 '05 #6
"Bernd Liebermann" <12**@bernd-liebermann.de> wrote in message news:<c1**********@online.de>...
Hi,

I have a problem with redirection using the header function. The page
towards which I redirect loads correctly, but the url in the browser's
address bar is different is that of the redirecting page. Both pages are
located in different directories, so that my relative links don't work in
the page, because the browser retrieves the current directory from the wrong
url in the location bar.
This problem occurs only on the server of my webhosting provider, not on my
local machine where I can see the correct url after redirection. So I
assume, this is a server specific setting. But how can I change ist?


/**----------------------------------------------------------------------------------
* Redirect2URL()-Redirects to the given URL
*
* @param $url - can be absolute/relative url eg.
http://foo.com/foo.htm or just foo.htm
* @return - void
**/
function Redirect2URL($url)
{
$url = trim($url);
//note: === (three equal signs)...otherwise it won't work
if ( ! preg_match("/^http:\/\/|https:\/\/|ftp:\/\//i", $url) ) //if
http:// is not found, then the url is relative...
$url = 'http://' . $_SERVER['HTTP_HOST'] .
(strpos($url, '/') === 0? $url :
(dirname($_SERVER['PHP_SELF']).'/'.$url));
header('Location: ' . $url); //use absolute URI
exit; // Make sure that code below does not get executed when we
redirect.
}/*---------Redirect2URL()-----------------------*/

This may work.

--
"Success is not what you achieve, but it is what you die for"
If you live in USA, please support John Edwards.
Email: rrjanbiah-at-Y!com
Jul 17 '05 #7
Thanks, this works perfect!

Bernd

"R. Rajesh Jeba Anbiah" <ng**********@rediffmail.com> schrieb im Newsbeitrag
news:ab**************************@posting.google.c om...
"Bernd Liebermann" <12**@bernd-liebermann.de> wrote in message news:<c1**********@online.de>...
Hi,

I have a problem with redirection using the header function. The page
towards which I redirect loads correctly, but the url in the browser's
address bar is different is that of the redirecting page. Both pages are
located in different directories, so that my relative links don't work in the page, because the browser retrieves the current directory from the wrong url in the location bar.
This problem occurs only on the server of my webhosting provider, not on my local machine where I can see the correct url after redirection. So I
assume, this is a server specific setting. But how can I change ist?


/**-------------------------------------------------------------------------
--------- * Redirect2URL()-Redirects to the given URL
*
* @param $url - can be absolute/relative url eg.
http://foo.com/foo.htm or just foo.htm
* @return - void
**/
function Redirect2URL($url)
{
$url = trim($url);
//note: === (three equal signs)...otherwise it won't work
if ( ! preg_match("/^http:\/\/|https:\/\/|ftp:\/\//i", $url) ) //if
http:// is not found, then the url is relative...
$url = 'http://' . $_SERVER['HTTP_HOST'] .
(strpos($url, '/') === 0? $url :
(dirname($_SERVER['PHP_SELF']).'/'.$url));
header('Location: ' . $url); //use absolute URI
exit; // Make sure that code below does not get executed when we
redirect.
}/*---------Redirect2URL()-----------------------*/

This may work.

--
"Success is not what you achieve, but it is what you die for"
If you live in USA, please support John Edwards.
Email: rrjanbiah-at-Y!com

Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Nick Whitelegg | last post: by
1 post views Thread by Webstyler | last post: by
5 posts views Thread by Ian | last post: by
1 post views Thread by chandra.somesh | last post: by
reply views Thread by comp.lang.php | last post: by
5 posts views Thread by One | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.