TIP - Getting server information about your user - Using CGI you can get a lot of information about your user like their domain name and IP address which you can log in a database or display on screen. It is easy to do this with app servers like ColdFusion and ASP, but to do it in Javascript is less documented but it can be done.
Here is a simple example of getting the user's IP address and displaying that back into an alert box.
<script> var ip = '<!-- #echo var="REMOTE_ADDR"-->'; alert("Your IP address is "+ip); </script>
You will need to save the file as .shtm or .shtml for the CGI portion to evaluate.
Here is a list of the variables available to you: (for IIS and from the IIS help system. For other servers, there are more variables you can access so check in your server's documentation.)
ALL_HTTP All HTTP headers AUTH_TYPE This contains the type of authentication used.
AUTH_PASSWORD The value entered in the client's authentication dialog box.
AUTH_USER The value entered in the client's authentication dialog box. CONTENT_LENGTH bytes that the script can expect to receive from the client. CONTENT_TYPE The content type of the information supplied in the body of a POST request.
DOCUMENT_NAME The current file name.
DOCUMENT_URI The virtual path to the current document.
DATE_GMT The current date in Greenwich Mean Time (GMT).
DATE_LOCAL The current date in the local time zone.
GATEWAY_INTERFACE The revision of the CGI specification used by the Web server.
HTTP_ACCEPT Special-case HTTP header.
LAST_MODIFIED The date that the current document was last modified.
PATH_INFO Additional path information consisting of the trailing part of the URL after the script name, but before the query string, if any.
PATH_TRANSLATED This is the value of PATH_INFO, but with any virtual path expanded into a directory specification.
QUERY_STRING The information that follows the question mark (?) in the URL that referenced this script.
QUERY_STRING_UNESCAPED Unescaped version of the query string; that is, a version that is not URL encoded.
REMOTE_ADDR The IP address of the client or agent of the client (for example, gateway or firewall) that sent the request.
REMOTE_HOST The host name of the client or agent of the client (for example, gateway or firewall) that sent the request. IIS 2.0 and 3.0 returned an IP address for this parameter.
REMOTE_USER This contains the user name supplied by the client and authenticated by the server. This comes back as an empty string when the user is anonymous (but authenticated).
REQUEST_METHOD The HTTP request method.
SCRIPT_NAME The name of the script program being executed.
SERVER_NAME The server’s host name, or IP address, as it should appear in self-referencing URLs. SERVER_PORT The TCP/IP port on which the request was received.
SERVER_PORT_SECURE A string of either 0 or 1. If the request is being handled on the secure port, this will be 1. Otherwise, it will be 0.
SERVER_PROTOCOL The name and version of the information retrieval protocol relating to this request. This is usually HTTP/1.0. The protocol is returned in the format name/version.
SERVER_SOFTWARE The name and version of the Web server answering the request. The server information is returned in the format name/version.
URL Gives the base portion of the URL. Parameter values will not be included. The value is determined when the Web server parses the URL from the header.
8:43:46 AM
|