AxKit::XSP::Cookie - An XSP library for setting and getting HTTP cookies. |
<cookie:create
><cookie:fetch
><cookie:name
><cookie:value
><cookie:path
><cookie:expires
><cookie:domain
><cookie:secure
>
AxKit::XSP::Cookie - An XSP library for setting and getting HTTP cookies.
Add the taglib to AxKit (via httpd.conf or .htaccess):
AxAddXSPTaglib AxKit::XSP::Cookie
Add the cookie: namespace to your XSP <xsp:page
> tag:
<xsp:page language="Perl" xmlns:xsp="http://apache.org/xsp/core/v1" xmlns:cookie="http://axkit.org/NS/xsp/cookie/v1" >
Then, put the taglib to work:
Set a cookie:
<cookie:create name="newCookie" value="somevalue" />
Get the value for a previous cookie:
<cookie:fetch name="oldCookie" />
The XSP cookie: tag library implements a simple way to set/get HTTP cookies.
In order to provide maximum flexibility for XSP developers, the cookie: taglib allows all of its arguments to be passed either
as attributes of the two 'wrapper' elements (<cookie:create
> and <cookie:fetch
>), or as child elements of the same.
In practice, the choice between passing arguments as attributes vs. passing them as child elements boils down to whether or not the value being passed is being set dynamically or not. If the arguments are hard-coded, you can safely pass the values as either an attribute or a child element. If, however, you need to pass a value that is not defined until run-time, you must use a child element since XSP does not allow the value of taglib attributes to be set dynamically. See the EXAMPLES below for clarification.
<cookie:create
>This tag is used to create a new HTTP cookie, or to update an existing one. As one of the cookie: lib's 'wrapper' elements this tag allows the following attributes or child elements:
Please see the descriptions below for the allowed values for each of these arguments.
<cookie:fetch
>The other, simpler of the two 'wrapper' elements this tag allows only the name attribute/child. The tag is used to retrieve the value of a prevously set cookie whose name matches the name argument.
<cookie:name
>When used as the child of a <cookie:create
> element this tag sets the cookie's name. When it used as the child of a
<cookie:fetch
> element it is used to define the name of the cookie to retrieve.
<cookie:value
>Allowed only as the child of a <cookie:create
> element, this tag defines the value for the cookie.
<cookie:path
>Allowed only as the child of a <cookie:create
> element, this tag defines the 'path' field for the cookie.
<cookie:expires
>Allowed only as the child of a <cookie:create
> element, this tag sets the cookie's expiry date. It accepts the same types
values that Apache::Cookie does.
<cookie:domain
>Allowed only as the child of a <cookie:create
> element, this tag defines the 'domain' field for the cookie.
<cookie:secure
>Accepting only the values of O or 1, this tag sets or unsets the cookie's 'secure' flag. It is allowed only as the child
of a <cookie:create
> element.
Fetch the value for a previous cookie whose name argument is hard-coded into the script:
<cookie:fetch name="chocolateChip"/>
Fetch the value for a previous cookie whose name is determined at run-time:
<cookie:fetch> <cookie:name><xsp:expr>$perl_var_containing_cookiename</xsp:expr></cookie:name> </cookie:fetch>
Set a cookie using only hard-coded arguments:
<cookie:create name="oatmealRaisin" value="tasty" expires="+3M" >
Set a cookie using a mix of dynamic child elements and static attributes:
<cookie:create name="peanutButter" domain=".mydomain.tld" secure="1" > <cookie:value><xsp:expr>$cookie_value</xsp:expr></cookie:value> <cookie:expires><xsp:expr>$cookie_expiry</xsp:expr></cookie:expires> <cookie:path><xsp:expr>$cookie_path</xsp:expr></cookie:path> </cookie:create>
As stated above, you can pass static arguments either as attributes or child elements of the enclosing tag. Thus:
<cookie:create name="pistachioChocolateChunk"/> ...
and
<cookie:create> <cookie:name>pistachioChocolateChunk</cookie:name> ...
are functionally equivalent.
Kip Hampton, khampton@totalcinema.com
Copyright (c) 2001 Kip Hampton. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AxKit, Apache::Cookie, CGI::Cookie
AxKit::XSP::Cookie - An XSP library for setting and getting HTTP cookies. |