Using Environment Variables
How to get some extra information
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 ?). Let's say the URL was:
http://yoursite.com/cgi-bin/testenv.cgi?cool
You 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:
| Name | What it Gets |
|---|---|
| CONTENT_LENGTH | Number of characters submitted from a POST command |
| HTTP_REFERER | URL user came from, if available. |
| HTTP_USER_AGENT | Type of Browser viewer is using, if available. |
| QUERY_STRING | String in URL after the ? character |
| REMOTE_ADDR | Remote user's IP address |
| REMOTE_HOST | Name of user's host, if available. |
| SERVER_NAME | Name of the local server, like: www.yoursite.com |
For more on environment variables, visit CGI 101, Chapter 3 for an excellent listing and tutorial.
Well, that's all for now, see you when I write the next section!
Other Topics:
ASP/PHP | DHTML | Java |
Site Survey |
Contact Us |
Privacy Policy
Copyright © 1997-2009 The Web Design Resource. All rights reserved. Disclaimer.
Copyright © 1997-2009 The Web Design Resource. All rights reserved. Disclaimer.
