header redirection and adress bar

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bernd Liebermann

    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


  • Wayne Pierce

    #2
    Re: header redirection and adress bar

    "Bernd Liebermann" <1234@bernd-liebermann.de> wrote in message news:<c18c8a$38 7$1@online.de>. ..[color=blue]
    > 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?[/color]

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

    /s/ WP

    Comment

    • Bernd Liebermann

      #3
      Re: header redirection and adress bar

      >[color=blue]
      > How are you redirecting the page? Can you post a code sample to look at?
      >
      > /s/ WP[/color]

      Sure.

      if ($some_conditio n) {
      header("locatio n:/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


      Comment

      • John Dunlop

        #4
        Re: header redirection and adress bar

        Bernd Liebermann wrote:
        [color=blue]
        > header("locatio n:/update/update1.php");[/color]

        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.
        [color=blue]
        > No characters sent to the page at that point.[/color]

        Right. The redirect wouldn't happen otherwise.
        [color=blue]
        > 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".[/color]

        (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?
        [color=blue]
        > I know that there are workaraounds like clientside redirection[/color]

        You misspelt "nasty hacks". :-)
        [color=blue]
        > or specifying <BASE> information in the html header.[/color]

        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:
        [color=blue]
        > But I would like to understand why this causes problems on my whp's server
        > and not my local pc.[/color]

        Will you provide a URL of a document demonstrating this?

        --
        Jock

        Comment

        • Bernd Liebermann

          #5
          Re: header redirection and adress bar

          [color=blue]
          > Will you provide a URL of a document demonstrating this?[/color]


          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


          Comment

          • John Dunlop

            #6
            Re: header redirection and adress bar

            Bernd Liebermann wrote:
            [color=blue]
            > 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.[/color]

            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

            Comment

            • R. Rajesh Jeba Anbiah

              #7
              Re: header redirection and adress bar

              "Bernd Liebermann" <1234@bernd-liebermann.de> wrote in message news:<c18c8a$38 7$1@online.de>. ..[color=blue]
              > 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?[/color]

              /**----------------------------------------------------------------------------------
              * 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($u rl)
              {
              $url = trim($url);
              //note: === (three equal signs)...otherw ise 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($_SERV ER['PHP_SELF']).'/'.$url));
              header('Locatio n: ' . $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

              Comment

              • Bernd Liebermann

                #8
                Re: header redirection and adress bar

                Thanks, this works perfect!

                Bernd

                "R. Rajesh Jeba Anbiah" <ng4rrjanbiah@r ediffmail.com> schrieb im Newsbeitrag
                news:abc4d8b8.0 402230148.22eac baa@posting.goo gle.com...[color=blue]
                > "Bernd Liebermann" <1234@bernd-liebermann.de> wrote in message[/color]
                news:<c18c8a$38 7$1@online.de>. ..[color=blue][color=green]
                > > 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[/color][/color]
                in[color=blue][color=green]
                > > the page, because the browser retrieves the current directory from the[/color][/color]
                wrong[color=blue][color=green]
                > > url in the location bar.
                > > This problem occurs only on the server of my webhosting provider, not on[/color][/color]
                my[color=blue][color=green]
                > > 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?[/color]
                >
                >[/color]
                /**-------------------------------------------------------------------------
                ---------[color=blue]
                > * 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($u rl)
                > {
                > $url = trim($url);
                > //note: === (three equal signs)...otherw ise 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($_SERV ER['PHP_SELF']).'/'.$url));
                > header('Locatio n: ' . $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[/color]


                Comment

                Working...