In the case of Apache, you get output similar to the following:
HTTP_USER_AGENT: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:126.96.36.199) Gecko/20070327 Ubuntu/dapper-security Firefox/188.8.131.52
SERVER_SIGNATURE: <address>Apache/2.0.55 (Ubuntu) mod_jk/1.2.14 mod_python/3.1.4 Python/2.4.3 PHP/5.1.2 Server at 192.168.0.2 Port 80</address>
SERVER_SOFTWARE: Apache/2.0.55 (Ubuntu) mod_jk/1.2.14 mod_python/3.1.4 Python/2.4.3 PHP/5.1.2
This for-loop will work on Python 2.4 and later. If it does not work for you, you may find that your Python installation needs updating. In the meantime, you can substitute these three lines for the one beginning "for k in...":
keys = os.environ.keys() keys.sort() for k in keys:
With either for-loop, you will get the same output. The result will be a small Python CGI script that you can use anywhere to figure out the environment in which you are programming. I should note in closing that parts of this tutorial were inspired by the coding of Jeff Bauer and Carey Evans and their script of a similar nature.