Hi, Yesterday I started working on an old program of mine which has a login/membership program.

I tried logging in and it worked and saved the cookies properly. I also tried creating a new user and it too saved the cookies properly, etc -- at least it appeared to be doing these things.

I didn't touch the login program. Last night I wanted to test a different part of the membership program. I logged in like I normally do, and it takes me to the menu page and prints out who I am along with the user id. But if I click on any of the links (ie. update profile, add an event, etc)it says that I am not logged in(!). I tried different user names, etc and I also tried creating a new profile (userid/password) ... it says that I'm not logged in though. I never touched the login program and I checked the settings for cookies on my computer ... everything looks good.

I am attaching the login program and also the subroutine that 'gets' the userid from the cookies.

Any ideas why the program suddenly went bezerk?

The problem must be either the way the cookies are set or the way they are beign retreived and read.

########################################################## ## 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 a +nd proceed if ($r[0] eq $psswd) { $cgi = new CGI; $session = new CGI::Session("driver:DB_File",undef,{Di +rectory=>'/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 = "<b>userid:$sesname</b>".$content; &PrintWebpage($content,"yes"); }

In reply to Problem with cookies by cranberry13

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.