UBB.Dev
Posted By: CNCR cookies - help me ?? - 07/08/2001 4:24 PM
ok guys, i no nothing about cookies, but i need to know about them for my script.

i want to make a cookie remember information for username, and password. in the $FORM{user} & $FORM{pass} feilds, when a user visits that page, if he has a cookie, it will automatically take him to a page.

any ideas?
Posted By: jordo Re: cookies - help me ?? - 07/08/2001 10:08 PM
well if your using cgi-lib (ie: this is in the top of your script: use CGI qw(:cgi-lib);) then you can use the nice prebuilt cookie functions:

to set a cookie (this has to happen before the content type line i believe):

$cookie = cookie(-name=> "cookiename", -value=> $FORM{user},);
print header(-cookie=>$cookie);


to read a cookie:

$cookie = cookie("cookiename");

you can set the value as an array too, so it can store a lot of data:

$cookie = cookie(-name=> "cookiename", -value=> [$FORM{user}, $FORM{pass}],);
print header(-cookie=>$cookie);

then read it like this:

@cookie = cookie("cookiename");

$user = $cookie[0];

$pass = $cookie[1];
© UBB.Developers