CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Advanced:
Cookie use with form



Jul 17, 2000, 1:27 PM

Post #1 of 2 (1692 views)
Cookie use with form Can't Post

Ok, the question is advanced, but my knowledge isnt, so go easy!

How can I set a cookie to store a userID and password, so that I can then call the cookie to automatically fill in html fields.

An example of this would be a user loging into a standard cgi password script, once authorised they could access the site, then if they clicked on forums they would only see a "Login" button (since the html field for the password etc is hidden and filled by the cookie)

Can somebody, anybody please tell me step by step how the heck to do this.

Please help, its for a real good cause.




Aug 1, 2000, 12:03 PM

Post #2 of 2 (1692 views)
Re: Cookie use with form [In reply to] Can't Post

sure.. i'll take a stab..

i tend to do things by hand, though nowadays directly implementing the http is sorta frowned on.

in order to set the cookie, do this:

print "Set-Cookie: uname=UserName; path=/;\r\n";
print "Set-Cookie: pass=thepassword; path=/;\r\n";

you should do that *just* before you set the content type:
print "Content-type: text/html\n\n";

note that if you don't set an expiration date, the cookie is 'volatile' and is erased when the browser is closed. if you DO set an expiration date, then the cookie will be written to the cookies.txt file, which may be an issue for you, since you're storing passwords. if that's the case, i strongly suggest you encrypt the password, using Crypt::CBC or something similar.

in order to get the cookies back to auto-fill the fields, you can use the CGI functions:

require CGI;
$username_cookie = CGI::cookie("uname");
$passwd_cookie = CGI::cookie("pass");

this will load the cookies into the specified locations, and you can then do whatever you want with them...

make sense?

again, you may want to think twice before setting password cookies in plaintext...


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives