Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: if statement based on HTTP_REFERRER

by Athanasius (Archbishop)
on Apr 09, 2015 at 17:18 UTC ( [id://1122975]=note: print w/replies, xml ) Need Help??


in reply to if statement based on HTTP_REFERER

Hello Jesse Smith,

Another point: Please note that it is both simpler and safer to avoid code duplication whenever possible:

my $db_name = $DATABASE2; my $suffix = 'NO HTTP_REFERRER'; if (defined $ENV{'HTTP_REFERRER'} && length $ENV{'HTTP_REFERRER'} > 0) { $db_name = $database; $suffix = "<A HREF=\"$ENV{'HTTP_REFERRER'}\">$ENV{'HTTP_REFERRER'} +</a>"; } $shortdate = `date +"%D %T %Z"`; chomp $shortdate; open(my $db, '>>', $db_name) or die "Cannot open database '$db_name' f +or appending: $!"; print $db "$ENV{'REMOTE_ADDR'} - $shortdate - $ENV{'HTTP_USER_AGENT'} +- " . "<A HREF=\"http://$ENV{'HTTP_HOST'}$ENV{'REQUEST_URI'}\">htt +p://$ENV{'HTTP_HOST'}$ENV{'REQUEST_URI'}</a> - $suffix\n"; close($db) or die "Cannot close database '$db_name': $!";

(Code untested, and with suggested improvements included: chomp instead of chop, the 3-argument form of open, a lexical filehandle, and testing for file open and close errors.)

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1122975]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-03-28 18:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found