CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Removing /document.extension from HTTP_REFERER



Sep 26, 2000, 10:58 PM

Post #1 of 2 (1004 views)
Removing /document.extension from HTTP_REFERER Can't Post

When someone clicks a link on a page that links to, the script will get the server name of the refering website using $ENV{'HTTP_REFERER'}. If I have the script print this out it looks like: HTTP_REFERER:

How can remove the /referingdocument.ext from (I think it can be done using regular expressions, but I am not sure)?

This way I can use
<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

if($servername eq "") {
#do something
} else {
#do something else
to see how many people are coming from where.

Could someone help?




Sep 27, 2000, 11:58 AM

Post #2 of 2 (1004 views)
Re: Removing /document.extension from HTTP_REFERER [In reply to] Can't Post

Warning: HTTP_REFERER can be forged. Do not use this as security.

If you have a URL, and you just want to extract the protocol and host, you can (and probably should) use the URI::URL module:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

use URI::URL;
my $url = URI::URL->new("");
$host = $url->host;
if ($host eq "") {
print "everything went as planned"
else {
print "something's messed up"

You might want to do:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

$front = $url->scheme . "://" . $url->host;

to get the "".

Or, you can roll your own solution:

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

($front) = $ENV{HTTP_REFERER} =~ m{
( # save to $1 (and return)
[^:]* # 0 or more non-: characters
:// # '://'
[^/]* # 0 or more non-/ characters

Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives