I have the following perl script.
I need it to invalidate all cookies that are not in the validCookies hash. Note this is only the upper part of my code, the rest deals with printing all the cookies in the @cookieArray() and that works for me.
Since the right cookies are being set that I need to set manually later on in the code. ATM the code is not invalidating the cookies, anyone see why?
use CGI qw(:standard);
use CGI::Cookie;
@cookieArray = ();
#hash of cookie names that should not be set to null
%validCookies = ( cName=> 0, cAddress => 0, cCity => 0, cProvince => 0, cPostalCode => 0, cMail => 0, cDate => 0);
%cook = CGI::Cookie->fetch;
foreach $name ($cook){
if(exists ($validCookies{$name})){
} else {
$temp = CGI::Cookie->new(-name=>$name, -value =>"");
push(@cookieArray, $temp);
}
}
To invalidate a cookie, you must expire it. The following code expires all except the protected cookie names.
It is not necessary to use the CGI::Cookie low-level interface. All the functionality is already exposed through the
cookiemethod.