########################################################## ## THIS PROCEDURE MAKES SURE THAT THE USER IS LOGGED IN ########################################################## sub CheckIfUserIsLoggedIn { use CGI::Session; my ($sid,$session,$userid); $cgi=new CGI; $sid=$cgi->cookie("CGISESSID")||undef; $session = new CGI::Session("driver:DB_File",$sid,{Directory=>'/tmp'}); $userid = $session->param("userid"); if ($userid eq "") { print "Content-type: text/html\n\n"; print "You are not logged in!! $userid\n\n"; exit; } else { return $userid; } } #################################################### The code below is from the login.pl routine that sets the cookie after checking that the password and username match what is in the DB: ## If the username and password are correct, then set cookie and proceed if ($r[0] eq $psswd) { $cgi = new CGI; $session = new CGI::Session("driver:DB_File",undef,{Directory=>'/tmp'}); $sid=$session->id(); $session->param("userid",$r[1]); $cookie=$cgi->cookie(CGISESSID=>$session->id); print $cgi->header(-cookie=>$cookie); $sesname=$session->param("userid"); $content = &Get_Account_Manager_html($r[1],$r[2],$r[3]); ## we pass the userid $content = "userid:$sesname".$content; &PrintWebpage($content,"yes"); }