Gadgets
Authentication
Crypto
ENV
HTTP
Regex
Regex 2
Robots
Snarfs
SSL
Stepper
|
Every good Webmaster knows how to capture the CGI environment
variables. By far the widest use of the environment variables
is capturing the browser type and version. The Perl CGI.pm
module (a standard part of the Perl library now) can fetch the
important ones.
#!/usr/bin/perl
use CGI;
my $query = new CGI;
$browser = $query->user_agent();
|
|
Or, it's easy enough to grab them all in their naked glory.
#!/usr/bin/perl
print "Content-type: text/html\n\n";
@keys = sort(keys %ENV);
foreach $key(@keys) {
print "$key = $ENV{$key}<BR>\n";
}
|
|
I'll caution you against putting this code on a server where people can find it.
It can expose things like paths on your server that hackers may be able to
exploit. But, assuming you can put it in a trusted place, you'd see output like the
following:
DOCUMENT_ROOT = /home/darkspel/www
GATEWAY_INTERFACE = CGI/1.1
HTTP_ACCEPT = image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
HTTP_ACCEPT_CHARSET = iso-8859-1,*,utf-8
HTTP_ACCEPT_ENCODING = gzip
HTTP_ACCEPT_LANGUAGE = en
HTTP_CONNECTION = Keep-Alive
HTTP_HOST = localhost
HTTP_PRAGMA = no-cache
HTTP_USER_AGENT = Mozilla/4.51 [en] (X11; I; Linux 2.2.5-15 i686)
PATH = /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin
QUERY_STRING =
REMOTE_ADDR = 127.0.0.1
REMOTE_PORT = 1073
REQUEST_METHOD = GET
REQUEST_URI = /cgi-bin/printenv.cgi
SCRIPT_FILENAME = /home/httpd/cgi-bin/printenv.cgi
SCRIPT_NAME = /cgi-bin/printenv.cgi
SERVER_ADMIN = root@localhost
SERVER_NAME = localhost.localdomain
SERVER_PORT = 80
SERVER_PROTOCOL = HTTP/1.0
SERVER_SIGNATURE =
SERVER_SOFTWARE = Apache/1.3.6 (Unix) (Red Hat/Linux) PHP/3.0.12 ApacheJServ/1.1b2
|
|
Next >>
|
|