env.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <html><head><title>CGI Environment Variables</title></head><body><h1><img alt="" src="env_files/CGIlogo.gif"> CGI Environment Variables</h1>
  2. <hr>
  3. <p>
  4. In order to pass data about the information request from the server to
  5. the script, the server uses command line arguments as well as
  6. environment variables. These environment variables are set when the
  7. server executes the gateway program. </p><p>
  8. </p><hr>
  9. <h2>Specification</h2>
  10. <p>
  11. The following environment variables are not request-specific and are
  12. set for all requests: </p><p>
  13. </p><ul>
  14. <li> <code>SERVER_SOFTWARE</code> <p>
  15. The name and version of the information server software answering
  16. the request (and running the gateway). Format: name/version </p><p>
  17. </p></li><li> <code>SERVER_NAME</code> <p>
  18. The server's hostname, DNS alias, or IP address as it would appear
  19. in self-referencing URLs. </p><p>
  20. </p></li><li> <code>GATEWAY_INTERFACE</code> <p>
  21. The revision of the CGI specification to which this server
  22. complies. Format: CGI/revision</p><p>
  23. </p></li></ul>
  24. <hr>
  25. The following environment variables are specific to the request being
  26. fulfilled by the gateway program: <p>
  27. </p><ul>
  28. <li> <a name="protocol"><code>SERVER_PROTOCOL</code></a> <p>
  29. The name and revision of the information protcol this request came
  30. in with. Format: protocol/revision </p><p>
  31. </p></li><li> <code>SERVER_PORT</code> <p>
  32. The port number to which the request was sent. </p><p>
  33. </p></li><li> <code>REQUEST_METHOD</code> <p>
  34. The method with which the request was made. For HTTP, this is
  35. "GET", "HEAD", "POST", etc. </p><p>
  36. </p></li><li> <code>PATH_INFO</code> <p>
  37. The extra path information, as given by the client. In other
  38. words, scripts can be accessed by their virtual pathname, followed
  39. by extra information at the end of this path. The extra
  40. information is sent as PATH_INFO. This information should be
  41. decoded by the server if it comes from a URL before it is passed
  42. to the CGI script.</p><p>
  43. </p></li><li> <code>PATH_TRANSLATED</code> <p>
  44. The server provides a translated version of PATH_INFO, which takes
  45. the path and does any virtual-to-physical mapping to it. </p><p>
  46. </p></li><li> <code>SCRIPT_NAME</code> <p>
  47. A virtual path to the script being executed, used for
  48. self-referencing URLs. </p><p>
  49. </p></li><li> <a name="query"><code>QUERY_STRING</code></a> <p>
  50. The information which follows the ? in the <a href="http://www.ncsa.uiuc.edu/demoweb/url-primer.html">URL</a>
  51. which referenced this script. This is the query information. It
  52. should not be decoded in any fashion. This variable should always
  53. be set when there is query information, regardless of <a href="http://hoohoo.ncsa.uiuc.edu/cgi/cl.html">command line decoding</a>. </p><p>
  54. </p></li><li> <code>REMOTE_HOST</code> <p>
  55. The hostname making the request. If the server does not have this
  56. information, it should set REMOTE_ADDR and leave this unset.</p><p>
  57. </p></li><li> <code>REMOTE_ADDR</code> <p>
  58. The IP address of the remote host making the request. </p><p>
  59. </p></li><li> <code>AUTH_TYPE</code> <p>
  60. If the server supports user authentication, and the script is
  61. protects, this is the protocol-specific authentication method used
  62. to validate the user. </p><p>
  63. </p></li><li> <code>REMOTE_USER</code> <p>
  64. If the server supports user authentication, and the script is
  65. protected, this is the username they have authenticated as. </p><p>
  66. </p></li><li> <code>REMOTE_IDENT</code> <p>
  67. If the HTTP server supports RFC 931 identification, then this
  68. variable will be set to the remote user name retrieved from the
  69. server. Usage of this variable should be limited to logging only.
  70. </p><p>
  71. </p></li><li> <a name="ct"><code>CONTENT_TYPE</code></a> <p>
  72. For queries which have attached information, such as HTTP POST and
  73. PUT, this is the content type of the data. </p><p>
  74. </p></li><li> <a name="cl"><code>CONTENT_LENGTH</code></a> <p>
  75. The length of the said content as given by the client. </p><p>
  76. </p></li></ul>
  77. <a name="headers"><hr></a>
  78. In addition to these, the header lines received from the client, if
  79. any, are placed into the environment with the prefix HTTP_ followed by
  80. the header name. Any - characters in the header name are changed to _
  81. characters. The server may exclude any headers which it has already
  82. processed, such as Authorization, Content-type, and Content-length. If
  83. necessary, the server may choose to exclude any or all of these
  84. headers if including them would exceed any system environment
  85. limits. <p>
  86. An example of this is the HTTP_ACCEPT variable which was defined in
  87. CGI/1.0. Another example is the header User-Agent.</p><p>
  88. </p><ul>
  89. <li> <code>HTTP_ACCEPT</code> <p>
  90. The MIME types which the client will accept, as given by HTTP
  91. headers. Other protocols may need to get this information from
  92. elsewhere. Each item in this list should be separated by commas as
  93. per the HTTP spec. </p><p>
  94. Format: type/subtype, type/subtype </p><p>
  95. </p></li><li> <code>HTTP_USER_AGENT</code><p>
  96. The browser the client is using to send the request. General
  97. format: <code>software/version library/version</code>.</p><p>
  98. </p></li></ul>
  99. <hr>
  100. <h2>Examples</h2>
  101. Examples of the setting of environment variables are really much better
  102. <a href="http://hoohoo.ncsa.uiuc.edu/cgi/examples.html">demonstrated</a> than explained. <p>
  103. </p><hr>
  104. <a href="http://hoohoo.ncsa.uiuc.edu/cgi/interface.html"><img alt="[Back]" src="env_files/back.gif">Return to the
  105. interface specification</a> <p>
  106. CGI - Common Gateway Interface
  107. </p><address><a href="http://hoohoo.ncsa.uiuc.edu/cgi/mailtocgi.html">cgi@ncsa.uiuc.edu</a></address>
  108. </body></html>