URL of Referring html Document 
May 12th, 2006, 04:55 AM
| | | 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(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. | 
May 12th, 2006, 08:05 AM
| | | 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 | 
May 12th, 2006, 08:35 AM
| | | Re: URL of Referring html Document
Nice one, thanks a lot. I'll check this out.
Pete. | 
May 12th, 2006, 02:15 PM
| | | 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. | 
May 12th, 2006, 02:45 PM
| | | 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 | 
May 12th, 2006, 05:45 PM
| | | 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 | 
May 13th, 2006, 04:25 AM
| | | 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. | 
May 13th, 2006, 08:05 PM
| | | 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 | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 220,989 network members.
|