Using Perl to get HTTP request headers
Before PHP and many new-age web scripting languages there was Perl. Today you can still use Perl for web development and it is included in xampp's web development suite.
In this post I will show you how to use the CGI module to get the HTTP request headers and then loop through them and print them out. This is handy if you want to know if a web visitor is using a proxy server etc.
The first line of code you need is the path to the Perl interpreter. In XAMPP it is:
#!C:\xampp\perl\bin\perl.exe
Next we include/use/set the CGI module, error reporting etc
use strict;
use warnings;
use CGI;
my $q = CGI->new;
my %headers = map { $_ => $q->http($_) } $q->http();
print "Content-type:text/html\r\n\r\n";
print "Got the following headers:\n";
for my $header ( keys %headers ) {
print "$header: $headers{$header}\n";
}
Comments
Post a Comment