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

Hi I use a server side include on a blank page to run a script. I then look at the env vars and make a decision as to what html to return. I use the exec cgi in the ssi. I have been unable to set a cookie in this manner. IS is possible. I know I could add a clear image to the page, but I would like to have it happen in one swoop if possible. thanks

Replies are listed 'Best First'.
Re: SSI & Cookies
by merlyn (Sage) on Dec 14, 2000 at 19:51 UTC
    The headers of an SSI (including Set-Cookie) never make it anywhere near the browser; they're strictly interpreted by the server. You'll have to have the browser fetch something (such as an image, or the next page) to include headers to set a cookie.

    -- Randal L. Schwartz, Perl hacker

Re: SSI & Cookies
by mirod (Canon) on Dec 14, 2000 at 17:09 UTC

    johnm, I don't want to sound too harsh, but you registered half an hour ago, just to post a question. That's fine, you are not the first one to do so and we are happy to welcome you on board, but if you had looked at the site a little bit you would have found a couple of things:

    • questions that get answers are usually much more precisely worded than yours, including a bit of code, whether you use CGI.pm, Apache & mod_perl, etc... all make it much more easy for people to answer.
    • there is a nifty Search field right at the top of the page, SSI Cookies retrieves a long, long list of posts on the subject. Did you check them?

    So I don't want you to think that we are a bunch of grumpy old misanthropes (most monks are much nicer than I am, just don't rub merlyn or tye the wrong way), but if you want this site to be useful for you I think you should spend a little time learning about it. It will make it much more enjoyable both for you and for the rest of the community.

    Don't take it too personnaly though, I guess you are paying for the numerous newcomers that behaved the same way, but that's the long explanation for the short -- on your post.

    And read those posts on SSI and Cookies...

Re: SSI & Cookies
by eg (Friar) on Dec 14, 2000 at 23:34 UTC

    There is a <furtive whisper>javascript</furtive whisper> solution here. Just add

    onload='document.cookie="name=whatever;expires=whenever";'
    

    to your <body> tag. Actually it doesn't even need to be in the <body>, it can be run at any point in your html.

    But if you sleep with the Devil, don't come crying to me when your child is born with two heads and a tail. :)