Using Environment VariablesHow to get some extra information![]() Home/CGI/Perl/Environment Variables Still another way to get input is through the use of environment variables. These are set outside the program, but can be read in pretty easily. For example, let's say we want to read the value of the Query String in the url (the part after the ? in a url). Let's say the url was:
http://yoursite.com/cgi-bin/testenv.cgi?coolYou could grab the "cool" bit off the url and assign it to a variable like this:
$iscool= $ENV{QUERY_STRING}; Using the $ENV{NAME} command, we can do the same to get other environment variables. We just replace the NAME with what we want to get, so:
$userip= $ENV{REMOTE_ADDR}; This will get the IP address of the user, which is useful in tracking a count for your unique visitors. Some other useful environment variables are listed below:
Well, that's all for now, see you when I write the next section!
The tutorials and articles on these pages are © 1997-2003 by John Pollock and may not be reposted without written permission from the author, and may not be reprinted for profit. |
![]() |
By: John Pollock |