![]() |
Practical mod_perl / HTML Version / | ![]() |
||
![]() |
||||
![]() |
![]() |
|||
![]() |
![]() |
|||
![]() |
||||
|
|
||||
![]() |
![]() |
|||
![]() |
E.3.2. Handling Cookies |
![]() |
||
![]() |
||||
![]() |
![]() |
![]() |
||
![]() |
||||
AxKit::XSP::Cookie is a taglib interface to Apache::Cookie (part of the libapreq package). The following example demonstrates both retrieving and setting a cookie from within XSP. In order for this to run, the following option needs to be added to your httpd.conf file:
AxAddXSPTaglib AxKit::XSP::Cookie
The XSP page is shown in Example E-4.
<xsp:page
xmlns:xsp="http://apache.org/xsp/core/v1"
xmlns:cookie="http://axkit.org/NS/xsp/cookie/v1"
language="Perl"
>
<page>
<xsp:logic>
my $value;
if ($value = <cookie:fetch name="count"/>) {
$value++;
}
else {
$value = 1;
}
</xsp:logic>
<cookie:create name="count">
<cookie:value><xsp:expr>$value</xsp:expr></cookie:value>
</cookie:create>
<p>Cookie value: <xsp:expr>$value</xsp:expr></p>
</page>
</xsp:page>
This page introduces the concept of XSP expressions, using the <xsp:expr> tag. In XSP, everything that returns a value is an expression of some sort. In the last two examples, we have used a taglib tag within a Perl if( )statement. These tags are both expressions, even though they don't use the <xsp:expr>syntax. In XSP, everything understands its context and tries to do the right thing. The following three examples will all work as expected:
<cookie:value>3</cookie:value> <cookie:value><xsp:expr>2 + 1</xsp:expr></cookie:value> <cookie:value><param:cookie_value/></cookie:value>
We see this as an extension of how Perl works—the idea of "Do What I Mean," or DWIM.
 
Continue to:
mod_perl, modperl, Apache, perl, cgi, html, mod_perl, e-commerce, scalability, free, open source, OSS, apache, squid, high availability, modperl, linux, unix, Web, www, mod_perl, webserver, admin, apache, book, webmaster, tools, modperl, guide, docs, documentation, help, mod_perl, perl, information, apache, script, errata, eric cholet, perl, apache, mod-perl, stas bekman, mod_perl, cool, perl, Apache, performance, speed, choice
![]() |
Other projects to check out: meta-religion.com is for those interested in Religious, Spiritual and Esoteric Phenomena. i-want-a-better.com is a community of people discussing what they would like to be improved in their lives and things they use and interact with. You may also want to find a healer in your area or read articles on variety of topics.