If you want a method that utilizes cookies that doesn't use any perl modules (although I recommend using modules), you can use this:

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 information

&cookieRead; ($cookie{'user'}, $cookie{'pass'}) = split (/::/, $cookie{'session'}); &loadUserSession($cookie{'user'});

a couple of things to point out:

1. If the user name or password contains a :: then this code could potentially break.

2. 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


In reply to Re: Authentication Suggestion in CGI by FitTrend
in thread Authentication Suggestion in CGI by tamilthambi2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.