http://qs321.pair.com?node_id=460637

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

i have a login page in shtml where a user logs in with his username and password .

i need to take care of session variable and for that i need to write a perl/cgi script which can take care of session variable and store it in database form on the server

the session variable to be taken care of are

1. Login name
2. password
3. time of login
4. time of logout
5. history of his login session
working on widows box

can i get any help how to proceed with it i am trying with CGI::Session. Please help me

Replies are listed 'Best First'.
Re: CGI perl
by Fletch (Bishop) on May 26, 2005 at 12:27 UTC

    Well, judging by the code you've shown . . . oh, never mind.

    Hint: Show effort, show what you've tried, and don't repost the same question three frelling times. No one here is going to write your script for you.

      use CGI::sesssion::File; use CGI; my $cgi = new CGI; my $sid = $cgi->cookie(SESSION_COOKIE) || $cgi->param("sid") || undef; //creating a new session my $session = new CGI::Session::File(undef {LockDirectory=>"/tmp", Directory=>"/tmp"}) or die $CGI::Session::errstr; print "Your session id is ", $session->id(); // A cookie is being created which is then being send to the user brow +ser $cookie = $cgi->cookie(CGISESSID => $session->id ); print $cgi->header(-cookie=>$cookie); $session->save_param($cgi, ["login_name", "password"]);

      i have tried to write this bit of code in which i try to collect the session variables from a HTML page and store in a database

      but i have few queries still 1. will my script run on windows or have to make some changes.
      2. there are some default session parameters values
      _sessio_id, _session_ctime, _session_atime, _session_etime
      how can i store this into the same database where my sessionid , loginname and password resides
      3.how can i set the expiration time for a user

Re: CGI perl
by xorl (Deacon) on May 26, 2005 at 12:33 UTC

    From what I can tell the following links tell you everything you need to know:
    http://search.cpan.org/~sherzodr/CGI-Session-3.95/Session.pm
    http://search.cpan.org/~sherzodr/CGI-Session-3.95/Session/Tutorial.pm
    http://search.cpan.org/~sherzodr/CGI-Session-3.95/Session/MySQL.pm
    http://search.cpan.org/~sherzodr/CGI-Session-3.95/Session/CookBook.pm

    I know this is blasphemy around here, but IMHO for any web application that needs some kind of session PHP is much better than Perl at handling it.

      I won't comment on Perl Vs PHP for handling sessions (since I've never written anything in Perl that uses sessions), but PHP does have insane default settings for its session handling. IIRC the developers won't change the defaults because they are terrified that browsers won't be able to handle HTML without any errors in it.

        I've just read that referenced node. Are you kidding me? PHP doesn't entitize the HTML in a link? Amazing. It's simply crazy that PHP hasn't fallen over with all the bad things still being done in it.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

Re: CGI perl
by fireartist (Chaplain) on May 26, 2005 at 15:06 UTC

    Are you sure a cgi script called via SHTML can get and set cookies?

        Well, I was pretty sure, but not certain! (And didn't have time to enable shtml on my server, etc...)