HTTP Session Variables
HTTP Session Variables
Some of the more useful environment variables can be
fetched through this interface. The methods are as follows:
Accept()
Return
a list of MIME types that the remote browser accepts. If you give this method a
single argument corresponding to a MIME type, as in
$query->Accept('text/html'), it will return a floating point value
corresponding to the browser's preference for this type from 0.0 (don't want) to
1.0. Glob types (e.g. text/*) in the browser's accept list are handled
correctly. Note the capitalization of the initial letter. This avoids conflict
with the Perl built-in accept().
auth_type()
Return
the authorization type, if protection is active. Example "Basic".
raw_cookie()
Returns
the "magic cookie" maintained by Netscape 1.1 and higher in a raw state. You'll
probably want to use
cookie()
instead, which gives you a high-level interface to the cookie functions. Called
with no parameters, raw_cookie() returns the entire cookie structure, which may
consist of several cookies appended together (you can recover individual cookies
by splitting on the "; " sequence. Called with the name of a cookie, returns the
unescaped value of the cookie as set by the server. This may be useful for
retrieving cookies that your script did not set.
path_info()
Returns
additional path information from the script URL. E.G. fetching
/cgi-bin/your_script/additional/stuff will result in $query->path_info()
returning "/additional/stuff". In addition to reading the path information, you
can set it by giving path_info() an optional string argument. The argument is
expected to begin with a "/". If not present, one will be added for you. The new
path information will be returned by subsequent calls to path_info(), and will
be incorporated into the URL generated by self_url().
path_translated()
As
per path_info() but returns the additional path information translated into a
physical path, e.g. "/usr/local/etc/httpd/htdocs/additional/stuff". You cannot
change the path_translated, nor will setting the additional path information
change this value. The reason for this restriction is that the translation of
path information into a physical path is ordinarily done by the server in a
layer that is inaccessible to CGI scripts.
query_string()
Returns
a query string suitable for maintaining state.
referer()
Return
the URL of the page the browser was viewing prior to fetching your script. Not
available for all browsers.
remote_addr()
Return
the dotted IP address of the remote host.
remote_ident()
Return
the identity-checking information from the remote host. Only available if the
remote host has the identd daemon turned on.
remote_host()
Returns
either the remote host name or IP address. if the former is unavailable.
remote_user()
Return
the name given by the remote user during password authorization.
request_method()
Return
the HTTP method used to request your script's URL, usually one of GET, POST, or
HEAD.
script_name()
Return
the script name as a partial URL, for self-refering scripts.
server_name()
Return
the name of the WWW server the script is running under.
server_software()
Return
the name and version of the server software.
virtual_host()
When
using the virtual host feature of some servers, returns the name of the virtual
host the browser is accessing.
server_port()
Return
the communications port the server is using.
user_agent()
Returns
the identity of the remote user's browser software, e.g. "Mozilla/1.1N
(Macintosh; I; 68K)"
user_name()
Attempts
to obtain the remote user's name, using a variety of environment variables. This
only works with older browsers such as Mosaic. Netscape does not reliably report
the user name!
http()
Called
with no arguments returns the list of HTTP environment variables, including such
things as HTTP_USER_AGENT, HTTP_ACCEPT_LANGUAGE, and HTTP_ACCEPT_CHARSET,
corresponding to the like-named HTTP header fields in the request. Called with
the name of an HTTP header field, returns its value. Capitalization and the use
of hyphens versus underscores are not significant.
For
example, all three of these examples are equivalent:
$requested_language = $q->http('Accept-language');
$requested_language = $q->http('Accept_language');
$requested_language = $q->http('HTTP_ACCEPT_LANGUAGE');
https()
The
same as http(), but operates on the HTTPS environment variables present when the
SSL protocol is in effect. Can be used to determine whether SSL is turned on.
|