473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 4830
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Nick Whitelegg | last post by:
Hello, I'm having an odd problem with combining an authentication session variable with header() redirection. Basically I have an authentication script which checks a username/password. If the...
0
by: Phil Powell | last post by:
Based upon the following articles: http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20708448.html http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_20717295.html...
1
by: Webstyler | last post by:
Hi, I must create a redirect : 1@mysite.com must open www.mysite.com and The url must remain 1 @mysite.com I have obtain redirect correctly with this code : <script language="Javascript">...
5
by: Ian | last post by:
Can anyone help with a problem I am having regarding redirection. I'm using the following php call to redirect users to a site and automatically enter the required login name and pass for the...
13
by: Raj | last post by:
Is there any way to delete a particular node from a singly linked list where the header of the list is unknown.Only pointer available is the one which points to the node to be deleted
3
by: maya | last post by:
yes I know, this has been asked many times, but I don't quite the answers: usu. answers are to put the redirect code -- in my case $URL =...
1
by: chandra.somesh | last post by:
I generally use Response.Redirect(url,false) for redirections. Is there a size constarint on the HTTP Response Location Header ? Also Is the behavior defined if we exceed this limit? In my...
0
by: comp.lang.php | last post by:
<? header('Pragma: no-cache'); // ENSURE CLIENT-SIDE CACHE FLUSHING $url = "$projectURLPath/index.php"; if ($_REQUEST) $url .= '?logoutMsg='. urlencode($_REQUEST); if ($willAuthenticate &&...
5
by: One | last post by:
Hi guys - I have a problem after a client clicks a Confirm button on a form - the form processes the data, inserts into a database, and then redirects using header Location. I have tested this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.