Getting actual url?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas -Balu- Walter

    Getting actual url?

    Hi guys...

    is there any way to get the actual called URL into a variable? I am not
    thinking of
    'http://'.$_SERVER['HTTP_HOST'].$_SERVER["SCRIPT_NAM E"].':'.$_SERVER["SERVER_POR T"]

    because this obviously does not differ e.g. between http: and https: or
    perhaps a user:pass-combo included in the url...

    Balu
  • Jan Pieter Kunst

    #2
    Re: Getting actual url?

    In article <c4c2pa$2g16rn$ 1@ID-62676.news.uni-berlin.de>,
    Thomas -Balu- Walter <netnews@b-a-l-u.de> wrote:
    [color=blue]
    > Hi guys...
    >
    > is there any way to get the actual called URL into a variable? I am not
    > thinking of
    > 'http://'.$_SERVER['HTTP_HOST'].$_SERVER["SCRIPT_NAM E"].':'.$_SERVER["SERVER_P
    > ORT"]
    >
    > because this obviously does not differ e.g. between http: and https: or
    > perhaps a user:pass-combo included in the url...[/color]

    What I usually do in these circumstances is:

    echo '<pre>';
    print_r($_SERVE R);
    echo '</pre>';
    die;

    And check the output for variables I could use.

    JP

    --
    Sorry, <devnull@cauce. org> is een "spam trap".
    E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.

    Comment

    • Thomas -Balu- Walter

      #3
      Re: Getting actual url?

      * Jan Pieter Kunst wrote:[color=blue]
      > In article <c4c2pa$2g16rn$ 1@ID-62676.news.uni-berlin.de>,
      > Thomas -Balu- Walter <netnews@b-a-l-u.de> wrote:
      >[color=green]
      >> is there any way to get the actual called URL into a variable? I am not
      >> thinking of
      >> 'http://'.$_SERVER['HTTP_HOST'].$_SERVER["SCRIPT_NAM E"].':'.$_SERVER["SERVER_P
      >> ORT"]
      >>
      >> because this obviously does not differ e.g. between http: and https: or
      >> perhaps a user:pass-combo included in the url...[/color]
      >
      > What I usually do in these circumstances is:
      >
      > echo '<pre>';
      > print_r($_SERVE R);
      > echo '</pre>';
      > die;
      >
      > And check the output for variables I could use.[/color]

      This is what I did (I used phpinfo(); though) and did not find a
      solution, thats why I asked here...

      Balu

      Comment

      • Ian.H

        #4
        Re: Getting actual url?

        On Wed, 31 Mar 2004 15:08:47 +0000, Thomas -Balu- Walter wrote:
        [color=blue]
        > * Jan Pieter Kunst wrote:[color=green]
        >> In article <c4c2pa$2g16rn$ 1@ID-62676.news.uni-berlin.de>,
        >> Thomas -Balu- Walter <netnews@b-a-l-u.de> wrote:
        >>[color=darkred]
        >>> is there any way to get the actual called URL into a variable? I am
        >>> not thinking of
        >>> 'http://'.$_SERVER['HTTP_HOST'].$_SERVER["SCRIPT_NAM E"].':'.$_SERVER["SERVER_P
        >>> ORT"]
        >>>
        >>> because this obviously does not differ e.g. between http: and https:
        >>> or perhaps a user:pass-combo included in the url...[/color]
        >>
        >> What I usually do in these circumstances is:
        >>
        >> echo '<pre>';
        >> print_r($_SERVE R);
        >> echo '</pre>';
        >> die;
        >>
        >> And check the output for variables I could use.[/color]
        >
        > This is what I did (I used phpinfo(); though) and did not find a
        > solution, thats why I asked here...
        >
        > Balu[/color]


        Would still require concatenation.. but you could use 'getservbyport' :


        $url =
        getservbyport($ _SERVER['HTTP_PORT']) . '://' . $_SERVER['HTTP_HOST'] .
        $_SERVER['SCRIPT_NAME'] . ':' .
        $_SERVER['HTTP_PORT'];


        This would detect 'http' or 'https' etc. As for user:pass combos, PHP has
        built in SuperGlobals to handle these too (PHP_AUTH_USER etc).


        HTH =)



        Regards,

        Ian

        --
        Ian.H
        digiServ Network
        London, UK


        Comment

        • Thomas -Balu- Walter

          #5
          Re: Getting actual url?

          In article <pan.2004.03.31 .15.35.23.14100 0@bubbleboy.dig iserv.net>, Ian.H wrote:[color=blue]
          > Would still require concatenation.. but you could use 'getservbyport' :
          >
          > $url =
          > getservbyport($ _SERVER['HTTP_PORT']) . '://' .
          > $_SERVER['HTTP_HOST'] .
          > $_SERVER['SCRIPT_NAME'] . ':' .
          > $_SERVER['HTTP_PORT'];
          >
          > This would detect 'http' or 'https' etc. As for user:pass combos, PHP
          > has
          > built in SuperGlobals to handle these too (PHP_AUTH_USER etc).[/color]

          getservbyport() just guesses the port by e.g. something like
          /etc/services? So if you have a testserver running on port 23 (you never
          know what wierd things admins do) it will report "telnet"?

          Nice idea, but still a little "luck" is needed to make that work
          globally.

          Balu

          Comment

          • Justin Koivisto

            #6
            Re: Getting actual url?

            Thomas -Balu- Walter wrote:
            [color=blue]
            > In article <pan.2004.03.31 .15.35.23.14100 0@bubbleboy.dig iserv.net>, Ian.H wrote:
            >[color=green]
            >>Would still require concatenation.. but you could use 'getservbyport' :
            >>
            >>$url =
            >> getservbyport($ _SERVER['HTTP_PORT']) . '://' .
            >> $_SERVER['HTTP_HOST'] .
            >> $_SERVER['SCRIPT_NAME'] . ':' .
            >> $_SERVER['HTTP_PORT'];
            >>
            >>This would detect 'http' or 'https' etc. As for user:pass combos, PHP
            >>has
            >>built in SuperGlobals to handle these too (PHP_AUTH_USER etc).[/color]
            >
            >
            > getservbyport() just guesses the port by e.g. something like
            > /etc/services? So if you have a testserver running on port 23 (you never
            > know what wierd things admins do) it will report "telnet"?
            >
            > Nice idea, but still a little "luck" is needed to make that work
            > globally.[/color]

            OK... I've been watching this thread hoping that I'd snag a better
            solution, but this is what I have been using:

            function getThisUrl(){
            if(isset($_SERV ER['HTTPS']) && strtolower($_SE RVER['HTTPS']=='on'))
            $url='https://';
            else
            $url='http://';
            if(isset($_SERV ER['PHP_AUTH_USER'])){
            $url.=$_SERVER['PHP_AUTH_USER'];
            if(isset($_SERV ER['PHP_AUTH_PW']))
            $url.=':'.$_SER VER['PHP_AUTH_PW'];
            $url.='@';
            }
            $url.=$_SERVER['HTTP_HOST'];
            if($_SERVER['SERVER_PORT']!=80 && $_SERVER['SERVER_PORT']!=443)
            $url.=':'.$_SER VER['SERVER_PORT'];
            $url.=$_SERVER['REQUEST_URI'];
            return $url;
            }


            --
            Justin Koivisto - spam@koivi.com
            PHP POSTERS: Please use comp.lang.php for PHP related questions,
            alt.php* groups are not recommended.
            SEO Competition League: http://seo.koivi.com/

            Comment

            • Thomas -Balu- Walter

              #7
              Re: Getting actual url?

              In article <W5Hac.217$m3.8 020@news7.onvoy .net>, Justin Koivisto wrote:[color=blue]
              > OK... I've been watching this thread hoping that I'd snag a better
              > solution, but this is what I have been using:[/color]

              Thanks for sharing your code, I was doing something like this myself by
              now and just thought I'd ask here to foind a better solution.

              If there is no other suggestion I am going to propose a feature request
              for a $_SERVER['FULL_URI'] or similar :)

              -- Balu

              Comment

              Working...