in reply to how to set a cookie without using CGI.pm?
Here is an alternative method I've used when playing with cookies and tracking a user's login session. I remember using this because for some reason I couldn't make it work based on some internet examples.
Here is the subs I used to read and write cookie information:
sub cookieRead { local(@rawCookies) = split (/; /,$ENV{'HTTP_COOKIE'}); foreach (@rawCookies) { ($key, $val) = split (/=/, $_); $cookie{$key} = $val; } } sub cookieWrite { local($name, $value, $expiration, $path, $domain, $secure) = @_; print "Set-Cookie: "; print ($name, "=", $value, "; path=", $path, "; domain=", $domain, + "; ", $secure, "\n"); }
Here is the code I use to write cookie information:
&cookieWrite("session", "$userName::$Password", "$expDate", "/cgi-bin/ +", "fittrend.com");
Here is the code I use to read cookie informaiton
&cookieRead; ($cookie{'user'}, $cookie{'pass'}) = split (/::/, $cookie{'session'}); &loadUserSession($cookie{'user'});
A fews flaws here that I personally worked around. If the user name or password contains a :: then this code could potentially break. Secondly, I recommend that you encrypt this information for security reasons. Using Crypt or another modules on cpan. Lastly, if you have a large amount of data, it won't fit on a single variable in the cookie. I just needed mine to track user name and password so I can use other code to load the entire user's profile from a MySQL back-end.
At the time, I was having problems with multiple variables in a cookie, so I simply delimited it. If I spent more time on it, I'd probably fix it.
Hope this helps
Marc
|
|---|