Connecting Tech Pros Worldwide Forums | Help | Site Map

URL of Referring html Document

Peter
Guest
 
Posts: n/a
#1: May 12 '06
Hi there, I am using this code to retrieve the current URL:

function selfURL() {
$s = empty($_SERVER["HTTPS"]) ? ''
: ($_SERVER["HTTPS"] == "on") ? "s"
: "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? ""
: (":".$_SERVER["SERVER_PORT"]);
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
Guest
 
Posts: n/a
#2: May 12 '06

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

Peter
Guest
 
Posts: n/a
#3: May 12 '06

re: URL of Referring html Document


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

Pete.

Peter
Guest
 
Posts: n/a
#4: May 12 '06

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.

NC
Guest
 
Posts: n/a
#5: May 12 '06

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

Gordon Burditt
Guest
 
Posts: n/a
#6: May 12 '06

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
Peter
Guest
 
Posts: n/a
#7: May 13 '06

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.php" 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.

Toby Inkster
Guest
 
Posts: n/a
#8: May 13 '06

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

Closed Thread