Mdc::Cookies version 1.00b -- 3:57 PM 2004-10-06
Routines to read CGI input, cookie and client type.
This module works in conjunction with the Mdc::CGI class. A CGI object must be created and passed to the ``new Mdc::Cookies'' method to create a new cookie object.
The Cookie module will maintain client cookies by storing them in local files within a cookie directory. A separate file for each client will be created. The client's cookie expiration date is reset uppon each visit and the cookie file is updated. The cookie will expire if the client has not visited your script for the number of days indicated by the expires value.
Once a month, the cookie directory is scanned for expired files so they can be deleted. The age of the cookie files are compared to the expiration_age value. An index file is created in the cookie directory which contains the date that the directory was last scanned.
The _directory_maintenance routine is also called uppon tying the hash. It's purpose is to scan the cookie directory once each day to remove expired cookie files. A maintenance file located in the cookie directory contains the date of the last file maintenance and other parameters the influence file maintenance.
Session cookie files are intended to save session state only. They contain the time of first and last access, the client's IP address and user agent information such as the browser type, version and the client's OS. This information is used by the Cookies module to determine when a session has expired.
Normally a session cookie that is sent to a web browser will automatically expire when the browser is closed. However, since the client's browser may never be closed for days, it is neccessary to force an expiration based on the time of last access. The default session time parameter is 90 minutes but this may be changed by the programmer.
Term cookies have a different purpose. There is no file associated with a term cookie. When a session is established, a term cookie is sent to the client's browser. The term cookie will then be used on subsequent visits to immediately establish a new session without the need to send a preliminary cookie again.
The term cookie value may be accessed with the $cookie{_TERM}{cookie_ID} and $cookie{_TERM}{cookie_IDvalue} attributes.
The purpose of a preliminary cookie is to verify that the client is accepting session cookies before a session is established. There is no file associated with a preliminary cookie. If a term cookie is returned then a session is established immediately and there is no need to send a preliminary cookie. However, the client's browser may not be accepting term cookies but will accept session cookies. The return of a preliminary cookie will signal that a session may be established.
use Mdc::CGI; my $CGI = new Mdc::CGI; use Mdc::Cookies; tie my %cookie, 'Mdc::Cookies', cgi_object=>$CGI ;
Tie a hash to the Mdc::Cookies class. Uppon tying a hash, the client cookie will be read. If no cookie is found, a new one will be created along with a corresponding cookie file located on the local server.
Clearing the hash by use of the %cookie=() method will have the effect of clearing the client cookie and removing the cookie file. However, if another value is assigned to the cookie hash prior to untying it or prior to script termination, the client cookie will be retained but the file contents will be cleared.
The cookie ID is the key name that the cookie value will be assigned to. If no cookie ID is defined, an internal default will used.
If a cookie ID is defined, the PATH value in the cookie header will be altered to allow other scripts to access the same client cookies. The only reason that you would want to define your own ID is if you are creating a series of separate scripts that must access the same cookie files.
range, 1 - 5 seconds
Range: 1 - 1440 Default: 15
A session will expire if the client's browser is closed or if a long enough period of inactivity has transpired. The actual session cookie header that is sent to the client will not contain an expiration value so the programmer does not have to be concerned that the client's system time or the server system time be syncronized. Relative time is used instead.
Mdc::Cookies Copyright (c) 2003 Mark K Mueller. All rights reserved. http://www.markmueller.com/