Important alert: (current site time 7/15/2013 9:04:33 PM EDT)
|
|
CGI environmental variables
|
Email
|
| Submitted on: |
6/17/2005 7:43:47 PM |
| By: |
Alexander Moore
|
| Level: |
Beginner |
| User Rating: |
Unrated |
| Compatibility: |
5.0 (all versions), Active Perl specific, 4.0 (all versions), 3.0 (all versions) |
| Views: |
7742 |
|
(About the author) |
|
|
|
Learn about the well known Perl environmental variables, which are used to store data taken from the user, the host, and the script itself, things like IP addresses and HTML headers.
|
| | Terms of Agreement:
By using this article, you agree to the following terms...
- You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
- You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
- You may link to this article from another website, but ONLY if it is not wrapped in a frame.
- You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
|
I'm aware this is well known, but I find it very useful information. No tutorial I have ever read has covered these in depth (I have not read every tutorial though.) This is good for beginners who wish to help improve their website.
CGI's come with environmental variables, variables which store information about the user, the host machine, and the script. Here is how they are employed: $ENV{'ENVIRONMENT_VARIABLE'};
For instance, if you wanted to manipulate the variable which stores the user's IP address, you would call $ENV{'REMOTE_ADDR'};To use one of the ones below, follow the above format and only use the text that's bolded where the variable name should go. Enough said, on with some examples. REMOTE_ADDR: Stores the IP address of the person who requested the document. REMOTE_PORT:Stores the port number from which the page is requested. I'm not sure what this is exactly, since it's for me never been the same as the port the host is on and generates a new number each time I run the script (after closing the web browser first). An interesting effect none the less. SERVER_NAME:Stores the name of the host that the script is on. SERVER_SOFTWAREStores the name of the program that the host uses to serve web pages. SERVER_PORT:The port from which the host is serving the web pages. ALL_HTTP: Stores the headers that the web browser sent to the script. AUTH_TYPE: The type of authentication used to verify the user's identity, if any. AUTH_USER:This displays the username the user entered if they were required to authenticate themselves to access the script. There is also a REMOTE_USER variable, but I have failed to experiment with this. QUERY_STRING: Stores all of the characters which appear in the URL after the question mark.
Your server also likely has it's own environmental variables. For these, you will need to check out your server's documentation. They are called in the same manner as CGI environmental variables. Lets say you want to print the user's IP address to the screen. The command would go like this:
print "$ENV{'REMOTE_ADDR'}";
Enjoy.
|
|
Report Bad Submission
|
Your Vote
|
| |
Other User Comments
|
There are no comments on this submission. |
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)
To post feedback, first please login.
|
|