
japhy
Enthusiast
Sep 27, 2000, 11:58 AM
Post #2 of 2
(1378 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("http://www.pobox.com/~japhy/"); $host = $url->host; if ($host eq "www.pobox.com") { print "everything went as planned" } else { print "something's messed up" } </pre><HR></BLOCKQUOTE> You might want to do: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> $front = $url->scheme . "://" . $url->host; </pre><HR></BLOCKQUOTE> to get the "http://www.pobox.com". 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 ) }x; </pre><HR></BLOCKQUOTE> ------------------ Jeff "japhy" Pinyan -- accomplished author, consultant, hacker, and teacher
|