Url of the calling page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mario Groleau

    #1

    Url of the calling page

    Hello,

    I is probably a trivial question, but I didn't find the answer.

    In a PHP 4 script, How to get the url of the page that called the script?

    Thank you very much in advance if you know the answer.
  • Chris Hope

    #2
    Re: Url of the calling page

    Mario Groleau wrote:
    [color=blue]
    > Hello,
    >
    > I is probably a trivial question, but I didn't find the answer.
    >
    > In a PHP 4 script, How to get the url of the page that called the script?[/color]

    Are you meaning the referring page? If so, $_SERVER['HTTP_REFERER']

    However, you cannot depend on this value being set, as the user may have
    come straight to your page from typing it in, copying and pasting or using
    a bookmark, or they may have a browser option or other software which
    prevents this information from being passed to the server.

    --
    Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

    Comment

    • Ian.H

      #3
      Re: Url of the calling page

      On 14 Oct 2004 16:14:05 -0700, mario.groleau@m groleau.ca (Mario Groleau)
      wrote:
      [color=blue]
      >Hello,
      >
      >I is probably a trivial question, but I didn't find the answer.
      >
      >In a PHP 4 script, How to get the url of the page that called the script?
      >
      >Thank you very much in advance if you know the answer.[/color]



      $callingURL = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];


      The HTTP_HOST should contain the domain details up to (but not
      including) the trailing slash. PHP_SELF should include the slash after
      the domain and any path to the script thereafter:





      HTTP_HOST would contain 'www.foo.com' and PHP_SELF would contain
      '/path/to/myscript.php'.

      If your URL happens to use a query string too:





      then $_SERVER['QUERY_STRING'] should contain everything from the '?'
      onwards.


      HTH =)



      Regards,

      Ian

      --
      Ian.H
      digiServ Network
      London, UK

      Comment

      • 2metre

        #4
        Re: Url of the calling page

        Mario Groleau wrote:
        [color=blue]
        > Hello,
        >
        > I is probably a trivial question, but I didn't find the answer.
        >
        > In a PHP 4 script, How to get the url of the page that called the script?
        >
        > Thank you very much in advance if you know the answer.[/color]

        $_SERVER["HTTP_REFER ER"]

        Comment

        Working...