Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old May 12th, 2006, 05:55 AM
Peter
Guest
 
Posts: n/a
Default 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.

  #2  
Old May 12th, 2006, 09:05 AM
Toby Inkster
Guest
 
Posts: n/a
Default 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
Default 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
Default 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
Default 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
Default 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
Default 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
Default 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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

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 205,338 network members.