Jump to content

Cookies As Html In Perl


Recommended Posts

Hey ya'll..


I recently updated one of my scripts to use cookies rather than form data to hold user info. After playing with it for a while, this was the solution I came up with. Just looking to see if there was a better way to do it.


User gets to a login page, enters their info and hits submit.

Before any text is sent back, I check for this:

routines later verify this information is correct.

I had to add the 301 header because it was just dumping the user back to the login screen, seems you can't write and read a cookie on the same page load.

setCookie just formats and sends the Set-Cookie html header with the included data.


if ($form{'username'}) {

&setCookie("poduser", "$form{'username'}", "$form{'password'}", "$form{'storenum'}", $myCookieExpires, $myCookiePath, $myCookieDomain);

print "Status: 301 Moved Permanantly\n";

print "Location: http://www.pen411.com/cgi-bin/pod.cgi\n\n";




here was the same deal, without the 301, it left the user at the last screen they were at until they tried to do something, then it realized they were logged out and dumped them back to the login screen.


if ($form{'action'} eq 'logout') {

&setCookie("poduser", "", "", "", "now", $myCookiePath, $myCookieDomain);

$loggedin = 0;

print "Status: 301 Moved Permanantly\n";

print "Location: http://www.pen411.com/cgi-bin/pod.cgi\n\n";


Any thoughts or suggestions are welcome, as this seems a clumsy way to make this work right.

Edited by Pendragon
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...