Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks,
To understand cookie setup better, I need the monks help.
The program flow as follows:
I have a home page(index.html) containing user login area (userid and password). On form submission I am calling a perl program(login.cgi) for user validation. If it validates, I should display User Account page , else display Error page.
To set cookie, the following code added to the login.cgi
use CGI qw(:standard); use CGI::Cookie; $q=new CGI; $cookie= $q->cookie(-name=>'DName', -value=>'userid', -expires=>'+72h' +, -path=>'/');

My doubt is that, once cookie set in the client browser and he call index.html page how can I point to User Account page (that is after the userid password validation process page)? In which program should I catch the cookie value?
$fetch= $q->cookie(-name=>'DName');

Can anyone please help me?
Thanks

Replies are listed 'Best First'.
Re: Help required on cookie set and get
by siva kumar (Pilgrim) on Jan 03, 2007 at 09:20 UTC
    You have a login screen. Enter user id and password. After submit call .cgi script to validate your user id and password.
    If they are correct then set cookie and redirect to "User Account page" by using
    print "Location: http://www.somewebsite.com";
    OR
    $q->redirect('http://www.somewebsite.com');
    Before display any authendication pages, check whether the cookie is exists or not. If not then redirect the page to login screen.
      siva kumar,
      Thanks a lot for your help.
      Still I am not clear, how the second time if the user call the home page, how it will point to User Account page?
      Step 1 : user type http://test.com/index.html
      step 2: enter userid and password and click on Submit button
      step 3: call cgi that checks whether cookie is present
      if not create cookie and call User Account Page
      else directly go to User Account page
      Close All pages

      Second time, if user type http://test.com/index.html
      will it point to User Account Page? Is it possible to do that?
      Thanks
Re: Help required on cookie set and get
by Anonymous Monk on Jan 03, 2007 at 09:31 UTC