Connecting Tech Pros Worldwide Help | Site Map

URL of Referring html Document

  #1  
Old May 12th, 2006, 05:55 AM
Peter
Guest
 
Posts: n/a
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.

  #2  
Old May 12th, 2006, 09:05 AM
Toby Inkster
Guest
 
Posts: n/a

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

  #3  
Old May 12th, 2006, 09:35 AM
Peter
Guest
 
Posts: n/a

re: URL of Referring html Document


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

Pete.

  #4  
Old May 12th, 2006, 03:15 PM
Peter
Guest
 
Posts: n/a

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.

  #5  
Old May 12th, 2006, 03:45 PM
NC
Guest
 
Posts: n/a

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

  #6  
Old May 12th, 2006, 06:45 PM
Gordon Burditt
Guest
 
Posts: n/a

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
  #7  
Old May 13th, 2006, 05:25 AM
Peter
Guest
 
Posts: n/a

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.

  #8  
Old May 13th, 2006, 09:05 PM
Toby Inkster
Guest
 
Posts: n/a

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ Topic - How do I get the value of a form control? FAQ server answers 17 January 1st, 2007 01:45 AM
using javascript closures to create singletons to ensure the survival of a reference to an HTML block Jake Barnes answers 2 February 12th, 2006 02:25 PM
document.write and buffer data Radek Maciaszek answers 12 July 23rd, 2005 08:26 PM
FAQ update (roundup of pending requests - for comment) Richard Cornford answers 42 July 20th, 2005 02:38 PM