in reply to How do I use HTTP Cookies?
I would guess by your last response, that you are not really getting this. So let me have a stab at the risk of being lambasted by those who know far more than I do.
Firstly, are you familiar with..
use CGI;
or are you still using some form of &read_form() subroutine to get your <form> data? If so, stop using it immediately (or sooner.)
Use this instead...
use CGI;
my $query = new CGI;
my $form_data = $query->param('field_name'); ## That's all you need to get form data
... and if you are wondering what the 'my' is, then you are NOT using 'strict'. Strict will more closely contol the 'scope' of your variables and will prevent stupid spelling mistakes.
ALL your CGI perl scripts should begin with...
use strict;
use CGI;
my $query = new CGI;
Most of the responses in this thread assume a knowledge of CGI. I use very little of CGI's capabilities. I mainly use it to get data from my <form> and cookies. So here's an easily understood approach to set and read a simple, session-persistant cookie.
Set a cookie:
my $cookie = "cookie_name=some_value"; # a cookie is simply a name/value pair
print "Content-Type: text/html\n";
print "Set-Cookie: $cookie\n\n";
Read a cookie:
my $cookie = $query->cookie('cookie_name'); # using CGI
Clear a cookie:
my $cookie = "cookie_name='';expires=01 Jan 2000 00:00:00";
This is really basic but should be enough to get you started. Next you will need to read up on cookies in general. There a lot more to learn.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do I use HTTP Cookies?
by Spidy (Chaplain) on Aug 30, 2004 at 21:26 UTC |