more useful options | |
PerlMonks |
Re^3: Setting and Reading Cookiesby gryphon (Abbot) |
on Jun 21, 2005 at 16:45 UTC ( [id://468749]=note: print w/replies, xml ) | Need Help?? |
Greetings rjsaulakh, Cookies are bits of text stored on the user's browser, which means that to "set" (write, save, put, etc.) a cookie, you have to send something to the browser. The browser sends cookie data (that you're allowed to view) in the HTTP header during a page request, which means that to "get" (read, fetch, etc.) a cookie, you have to have the browser send you something. In the world of CGI scripts, you have to get something from the browser (the request) before you can send something to the browser (the response). So you can't both set and read a cookie in the same script in the same request/response event. You have to first write the cookie in one response, then and only thereafter can you read the cookie. Here's an example:
The first time you hit this CGI, you'll get "Cookie Data: No Cookie Set." However, reload the page and you'll get "Cookie Data: Darth Vadar." gryphon
In Section
Seekers of Perl Wisdom
|
|