![]() |
CGI-Perl Tips
How to direct a browser to display a different HTML page This is actually very simple to do in a CGI script. Instead of the usual header
Code: PERL
How to manipulate browser caching Using an Expires header is the best way of achieving this in most cases. Specify a date in the past, and the browser will think the page must be updated next time it requires it. You can also specify to certain browsers that they should not cache this document by returning a no-cache pragma. The pragma is returned as part of your header. For example, your script might return Code: PERL
Code: PERL
Code: PERL
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. raw_cookie() Returns the HTTP_COOKIE variable, an HTTP extension implemented by Netscape browsers version 1.1 and higher. Cookies have a special format, and this method call just returns the raw form (?cookie dough). See cookie() for ways of setting and retrieving cooked cookies. user_agent() Returns the HTTP_USER_AGENT variable. If you give this method a single argument, it will attempt to pattern match on it, allowing you to do something like $query->user_agent(netscape); 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". 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''. remote_host() Returns either the remote host name or IP address. if the former is unavailable. script_name() Return the script name as a partial URL, for self-refering scripts. referer() Return the URL of the page the browser was viewing prior to fetching your script. Not available for all browsers. auth_type () Return the authorization/verification method in use for this script, if any. server_name () Returns the name of the server, usually the machine's host name. virtual_host () When using virtual hosts, returns the name of the host that the browser attempted to contact. server_software () Returns the server software and version number. remote_user () Return the authorization/verification name used for user verification, if this script is protected. user_name () Attempt to obtain the remote user's name, using a variety of different techniques. This only works with older browsers such as Mosaic. Netscape does not reliably report the user name! request_method() Returns the method used to access your script, usually one of 'POST', 'GET' or 'HEAD'. Creating a self-referencing URL which preserves state information: Code: PERL
Code: PERL
Code: PERL
Code: PERL
|
| All times are GMT +5.5. The time now is 08:44. |