Transcript CGI Environment Variables - London South Bank University
Outcomes
• Know what are CGI Environment Variables • Know how to use environment variables • How to process A simple Query Form • Able to use URL Encoding rules in your perl program • Able to use Split function to extract information • Understand what is CGIWRAP
CGI Environment Variables
• Environment variables is a set of hidden values that Web server sends to every CGI you run.
• You CGI program can parse them, and use the data you send • Environment variables are stored in a hash called %ENV • The %ENV hash is automatically set for every CGI, and you can use any or all of it as needed
• • • • • • • • • • •
CGI Environment variables
Environment variables are a series of hidden values that the web server sends to every CGI you run. Your CGI can parse them, and use the data they send.
Variable Name Value
DOCUMENT_ROOT HTTP_COOKIE HTTP_HOST The root directory of your server The visitor’s cookie, if one is set The hostname of your server HTTP_REFERER HTTP_USER_AGENT HTTPS The URL of the page that called your script The browser type of the visitor "on" if the script is being called through a secure server PATH QUERY_STRING REMOTE_ADDR The system path your server is running under The query string (see GET, below) The IP address of the visitor
• • • • • • • • • • • •
CGI Environment variables
REMOTE_HOST REMOTE_PORT REMOTE_USER REQUEST_METHOD REQUEST_URI The hostname of the visitor (if your server has reversename-lookups on; otherwise this is the IP address again) The port the visitor is connected to on the web server The visitor’s username (for .htaccess-protected pages) GET or POST The interpreted pathname of the requested document or CGI SCRIPT_FILENAME (relative to the document root) The full pathname of the current CGI SCRIPT_NAME SERVER_ADMIN SERVER_NAME The interpreted pathname of the current CGI (relative to the document root) The email address for your server’s webmaster Your server’s fully qualified domain name SERVER_PORT The port number your server is listening on SERVER_SOFTWARE The server software you’re using (such as Apache 1.3)
Examples of useful Environment variables
(env.cgi)
#!/usr/bin/perl print "Content-type:text/html\n\n";
print <
\n"; } print "