views:

60

answers:

2

Would like to set cookies from the server (CGI - C)
Can it be set after the header has been printed?

Thanks.

+2  A: 

You can set cookies using JavaScript embedded in an HTML document, or via a few other mechanisms, such as Flash.

Other than that though, the header is the only place in HTTP you can set them.

David Dorward
Note that setting cookies in the header and using the HTTPOnly flag is helpful for security - it prevents JavaScript code from reading the cookie, which can stop XSS attacks from hijacking the user's session by stealing their cookies. See http://www.owasp.org/index.php/HTTPOnly and the slightly dated http://www.codinghorror.com/blog/archives/001167.html
aem
+4  A: 

Not directly, cookies that come directly from the server must be explicitly set in the response header using Set-Cookie. See here for a thorough explanation.

AndiDog
how do you do this "indirectly" ?
Tommy
By "indirectly", I mean all forms of setting a cookie without the HTTP header. For example on the client side, like David Dorward already pointed out.
AndiDog