in reply to SSI and *reading* a cookie only

How complicated does your cookie check need to be? If HTTP_COOKIE is set in your enviroment you can check to see if something is set like this:

<!--#if expr="$HTTP_COOKIE = /foo\=bar/"--> <p>Cookie foo is set to bar</p> <!--#endif -->

If you need something more complicated you could use exec or virtual to run a cgi.

foo.shtml

<html> <body> <p>Test of include</p> <!--#include virtual="/cgi-bin/bar.pl" --> </body> </html>

bar.pl

#!/usr/bin/perl -w use strict; use CGI; my $cgi = CGI->new(); print $cgi->header, $cgi->start_html; my @names = $cgi->cookie(); foreach my $c ( @names ) { my $val = $cgi->cookie( $c ); print $cgi->blockquote( $cgi->em( $c ), ' - ', $val ); }
-derby

Replies are listed 'Best First'.
Re^2: SSI and *reading* a cookie only
by jfrm (Monk) on Jun 17, 2005 at 20:43 UTC
    Thank you for answering. I don't think this works as far as I can see, though. Perhaps I'm being dense.

    Keeping it simple, my SSI script uses the cookie to lookup a person's session file and thus determine if a person is in the EU, US or UK. If the person is from the US, it displays a US flag and a price in US$, if EU, an EU flag and a price in Euros etc. But since it can't get at the cookie, it can't get the person's session file and so cannot determine what to display.

    I have already set up a test SSI which calls a virtual in the way you suggest. It works but doesn't do anything except show the current ENV variables. I pasted in the code exactly as you have it but without the header and start_html as I already had these. It didn't show anything and a print of @names showed that @names was empty.

    I don't use CGI module so am not too familiar but surely if a perl script called by SSI virtual finds the HTTP_COOKIE environment variable undefined, surely the CGI module will find the same thing when calling cgi->cookie(), won't it?

    thanks,

    P&DM.