I have spent another two hours trying to figure this out ... i could spend some more time but I'm going to throw something soon if I don't figure this out.
I've looked at a lot of examples ... most of them do the following:
These examples frusturate me so much -- why would anyone be interested in retrieving the cookie info that they just set??!!?
Which leads me to my question.
In every other script after the person logs in (login.pl) I check whether the user is logged in. I create the session object and try to retrieve the userid (which I previously stored). If the userid is empty, then the person is not logged in (right?). If the userid exists, it's a flag that the person is logged in and I have go ahead and retrieve sensitive info from the my DB and display it to the screen.
Here is the code for when the user logs in (sets the user id cookie and sessionid):
## step 1. take the username and password from the form ## step 2. query the mysql db and check to see whether the password i +s good for the username ## Now create session id and set cookies ..... $cgi = new CGI; $session = new CGI::Session("driver:DB_File",undef,{Di +rectory=>'/tmp'}); $sid=$session->id(); $session->param("userid",$newuserid); $cookie=$cgi->cookie(CGISESSID=>$session->id); print $cgi->header(-cookie=>$cookie); $cookieuserid=$session->param("userid"); ## now we can display anything to them because they just logged in
And here is the code in a procedure that i call at the beginning of every script in my cgi-bin (excluding login.pl) that checks to see whether the user is logged in. The userid is the flag that determines whether they're logged in or not.
sub CheckIfUserIsLoggedIn { use CGI::Session; my ($sid,$session,$userid); $cgi=new CGI; $sid=$cgi->cookie("CGISESSID")||undef; $session = new CGI::Session("driver:DB_File",undef,{Directory=>'/tmp'} +); $userid = $session->param("userid"); if ($userid eq "") { print "Content-type: text/html\n\n"; print "You are not logged in!!\n\n"; exit; } else { ## display whatever I want to this user } }
What am i doing wrong? The statement "You're not logged in" keeps appearing. <sigh> You guys are great <sniff>
In reply to one last question about CGi session by cranberry13
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |