Download: source (zip file)
When we run a CGI program, we usually pass it some data from the browser. This data is read by the CGI program from its environment variables and, if it is called with a POST method, from its standard input.
For example, the environment variable
is set to either
on the type of request.
Other environment variables that are often present (but not always) are
|HTTP_REFERER||The URL of the document that contained the reference to this CGI program (present only if a referring page exists)|
|REMOTE_ADDR||The IP address of the user's machine (almost always present)|
Footnote: Is it requestor (as used here) or requester? A google search on the distinction is inconclusive, both terms seem correct. Maybe this is an "American" English vs. "British" English issue.
#!/usr/bin/python import os print 'Content-Type: text/html' print print '<html>' print '<head><title>Requestor</title></head>' print '<body>' print '<h2>Hello requestor</h2>' r = os.environ.get('HTTP_REFERER') if r: print '<p>You were referred by page:',r,'</p>' r = os.environ.get('REMOTE_ADDR') if r: print '<p>Your internet address is',r,'</p>' print '</body></html>'
Follow test link: test
Maintained by John Loomis, updated Tue Jan 29 21:09:25 2008