apprentice has asked for the wisdom of the Perl Monks concerning the following question:

I am working with a website that wants mostly static pages which may use SSI's. To do some of the things they want, I need to be able to set a cookie from some pages.

Does anyone know if it's possible to use CGI.pm or some other method to set a cookie from a cgi called by an ssi 'include virtual' directive in a web page?

Alternate suggestions welcome.

Thanks!

"Peace, love, and Perl...well, okay, mostly just Perl!" --me
Apprentice

Replies are listed 'Best First'.
•Re: Setting cookie via included CGI?
by merlyn (Sage) on Jan 10, 2003 at 17:16 UTC
    The headers from an SSI are mostly ignored, except that they have to be valid (and might contain an internal redirect, which is processed). They don't leak through into the return HTTP reply, so you can't set cookies from there.

    If you need to set a cookie, you need to have the page control the header somehow... so either generate it from CGI, or something cooler, like HTML::Mason or Template.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

(z) Re: Setting cookie via included CGI?
by zigdon (Deacon) on Jan 10, 2003 at 17:13 UTC

    To set a cookie, the script needs to output it in the header of the responce, before any text is sent. So unless your SSI can be told not to output anything at all until the CGI is finished, I don't see how you could set it from a pure perl solution.

    Of course, you should be able to have your CGI output a bit of javascript, that will set the cookie for you.

    -- zigdon

Re: Setting cookie via included CGI?
by Aristotle (Chancellor) on Jan 12, 2003 at 01:35 UTC
    You might be able to cook something up using mod_headers, but it won't be trivial. Update: or maybe mod_cern_meta, but YMMV.

    Makeshifts last the longest.