URL of Referring html Document

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

    URL of Referring html Document

    Hi there, I am using this code to retrieve the current URL:

    function selfURL() {
    $s = empty($_SERVER["HTTPS"]) ? ''
    : ($_SERVER["HTTPS"] == "on") ? "s"
    : "";
    $protocol = strleft(strtolo wer($_SERVER["SERVER_PROTOCO L"]), "/").$s;
    $port = ($_SERVER["SERVER_POR T"] == "80") ? ""
    : (":".$_SERVE R["SERVER_POR T"]);
    return
    $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
    }
    function strleft($s1, $s2) {
    return substr($s1, 0, strpos($s1, $s2));
    }

    which returns the URL of the current PHP script.

    But, I would like it to return the URL of the html page that preceeded
    this script.

    I mean, I have a some html pages with some photos. I have a form that
    allows users to enter an email address that will then send the link of
    that html page to the email address used.

    When I use the above it only shows the address of the page that
    executed the command, not the original html document.

    Can this even be done?

    Thanks,

    Peter.

  • Toby Inkster

    #2
    Re: URL of Referring html Document

    Peter wrote:
    [color=blue]
    > But, I would like it to return the URL of the html page that preceeded
    > this script.[/color]

    Look at $_SERVER['HTTP_REFERER'] (sic). But you can't trust it because it
    comes from the browser, and not all browsers will set it.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact

    Comment

    • Peter

      #3
      Re: URL of Referring html Document

      Nice one, thanks a lot. I'll check this out.

      Pete.

      Comment

      • Peter

        #4
        Re: URL of Referring html Document

        Yep, works well, thanks. I tested on IE6, FF1.0.4 and Opera8.01 and
        they all handle the HTTP_REFERER function.

        Comment

        • NC

          #5
          Re: URL of Referring html Document

          Peter wrote:[color=blue]
          >
          > I am using this code to retrieve the current URL:
          >
          > function selfURL() {[/color]
          ....[color=blue]
          > }
          >
          > which returns the URL of the current PHP script.[/color]

          Why? What's wrong with $_SERVER['SCRIPT_URI']?
          [color=blue]
          > But, I would like it to return the URL of the html page
          > that preceeded this script.[/color]

          That would be $_SERVER['HTTP_REFERER'].

          Cheers,
          NC

          Comment

          • Gordon Burditt

            #6
            Re: URL of Referring html Document

            >Yep, works well, thanks. I tested on IE6, FF1.0.4 and Opera8.01 and[color=blue]
            >they all handle the HTTP_REFERER function.[/color]

            Test it with firewalls in operation and you'll notice that HTTP_REFERER
            can be deleted or faked. Further, there's a good chance a Windows
            user won't be able to turn off that operation in the firewall even
            if they wanted to.

            Gordon L. Burditt

            Comment

            • Peter

              #7
              Re: URL of Referring html Document

              Hi NC, I tried the $_SERVER['SCRIPT_URI'] but it returns NULL. E.g I
              have an html page with a form like this:

              <form action="refer.p hp" method="post">
              <p>First Name</br><input type="text" name="name" size="20"
              maxlength="40"/></p>
              <p><input type="submit" name="submit" value="Send Message"/></p>
              </form>

              And then this is my php code:

              <?php
              $refer = $_SERVER['SCRIPT_URI'];
              echo $refer;
              ?>

              But it comes back blank.

              I would like it to return the full html URL like the HTTP_REFERER does
              but seems that it is not to be relied on.

              I think it will be best to use a hidden form on each page that contains
              the URL and the just get this.... for reliability.

              It's just that I have to then edit each page individually to add the
              hidden value.

              Thanks a lot though!

              Pete.

              Comment

              • Toby Inkster

                #8
                Re: URL of Referring html Document

                Peter wrote:
                [color=blue]
                > Yep, works well, thanks. I tested on IE6, FF1.0.4 and Opera8.01 and
                > they all handle the HTTP_REFERER function.[/color]

                Opera > Quick Prefs (F12) > Enable referer logging > Disable

                --
                Toby A Inkster BSc (Hons) ARCS
                Contact Me ~ http://tobyinkster.co.uk/contact

                Comment

                Working...