473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

confusion over is_expired and is_empty in CGI:Session

170 100+
hey guys,
i'm not sure if u guys have place this problem before

i did an expiration of my CGI session for 1 min

and i got the code below to detect
Expand|Select|Wrap|Line Numbers
  1. if($session->is_expired)
  2.   {
  3.       print $cgi->header(-cache_control=>"no-cache, no-store, must-revalidate");
  4.       print "<p>Your has session expired. Please login again.<p></br>";
  5.       print "<a href='http://localhost//cgi-bin//mml%20log//login.pl'>Login</a>";
  6.   }
  7.   elsif ($session->is_empty)
  8.   {
  9.  
  10.       print $cgi->header(-cache_control=>"no-cache, no-store, must-revalidate");
  11.       print "You have not logged in";
  12.   }
  13.  
the problem is i know when the session expires, it deletes the session off
now when it expires instead of printing "your session expired"
it keeps printing you have not logged in

so i'm wondering if there's anything wrong with the is_expired function
May 30 '08 #1
7 2685
eWish
971 Expert 512MB
is_expired()

Tests whether session initialized using load() is to be expired. This method works only on sessions initialized with load():
Are you using this function correclty?

--Kevin
Jun 5 '08 #2
numberwhun
3,509 Expert Mod 2GB
Did you initialize the session using the load() function? If not, then using the is_expired() function is no use as it only works for sessions initialized with load();.

Regards,

Jeff
Jun 5 '08 #3
poolboi
170 100+
yup i did
ok let me show u my logi script
ignore the ##username## and ##password## portion, i need to mask it off
so this is my log in page

Expand|Select|Wrap|Line Numbers
  1. #!/perl/bin/perl
  2.  
  3. use strict;
  4. use DBI();
  5. use CGI;
  6. use CGI::Session(' ip_match ');
  7. use Digest::SHA1 qw(sha1);
  8.  
  9. my ($dbh, $sth, $name1, $name2, $session);
  10.  
  11. my $cgi = new CGI;
  12.  
  13. my $username = $cgi->param('username');
  14. my $password = $cgi->param('password');
  15.  
  16. if($username ne '')
  17. {
  18. $dbh = DBI->connect("DBI:mysql:database=authentication;host=localhost","##username##","##password##", 
  19.               {RaiseError => 1});
  20.  
  21. $sth = $dbh ->prepare("SELECT * FROM `example` WHERE Username='$username' AND Password=SHA1('$password')");
  22. $sth->execute();
  23. while (my $ref =$sth->fetchrow_hashref()) {
  24. $name1 = $ref->{'Username'}, $name2 = $ref->{'Password'};}
  25.  
  26.  
  27.  
  28. if ($username eq $name1 && ($username))
  29.     {
  30.        $session = new CGI::Session();
  31.        print $session->header(-location=> "http://localhost//cgi-bin//mml%20log//element_select.pl");
  32.     }
  33.     else
  34.     {
  35.     print
  36.     $cgi->header,
  37.     $cgi->start_html(-title=>'StarHub Login');
  38.  
  39. print <<HTML;
  40. <FORM METHOD="GET">
  41. <div style="height100%; width100%; z-index:-1; position:absolute; top:0px; bottom:0px">
  42. <IMG SRC="C:\\Program Files\\Apache Software Foundation\\Apache2.2\\
  43.                         htdocs\\starhub1024by768.jpg" ALT="starhub">
  44. </div>
  45. <div style="position:absolute; top:223px"> 
  46. <p>You have Entered an Incorrect password or username</p>
  47. <p>Please Log in below:</p>
  48. <p>Username: <INPUT TYPE=TEXT NAME="username"></p>
  49. <p>Password: <INPUT TYPE=PASSWORD NAME="password"></p></br>
  50. <INPUT TYPE=SUBMIT name=QUERY2 value="Log In"> 
  51. <a href="http://localhost//cgi-bin//mml%20log//passwordchange.pl">Forget your Password?</a>
  52. </div>
  53. </FORM>
  54. HTML
  55.  
  56. print $cgi->end_html();
  57.  
  58.     }
  59. $dbh->disconnect();
  60.  
  61. }
  62. elsif($cgi->param('action') eq 'logout')
  63.      {
  64.      $session = CGI::Session->load() or die CGI::Session->errstr;
  65.            $session->delete();
  66.            print $session->header(-location=>"http://localhost//cgi-bin//mml%20log//login.pl");
  67.      }
  68.      else
  69.      {    
  70.  
  71. print
  72.     $cgi->header,
  73.     $cgi->start_html(-title=>'StarHub Login');
  74.  
  75. print <<HTML;
  76. <FORM METHOD="GET">
  77. <div style="height100%; width100%; z-index:-1; position:absolute; top:0px; bottom:0px">
  78. <IMG SRC="C:\\Program Files\\Apache Software Foundation\\Apache2.2\\
  79.                         htdocs\\starhub1024by768.jpg" ALT="starhub">
  80. </div>
  81. <div style="position:absolute; top:223px"> 
  82. <p>Please Log in below:</p>
  83. <p>Username: <INPUT TYPE=TEXT NAME="username"></p>
  84. <p>Password: <INPUT TYPE=PASSWORD NAME="password"></p></br>
  85. <INPUT TYPE=SUBMIT name=QUERY2 value="Log In"> 
  86. </div>
  87. </FORM>
  88. HTML
  89.  
  90. print $cgi->end_html();
  91. }
  92.  
if login successful
i direct it to this script

Expand|Select|Wrap|Line Numbers
  1. #!/perl/bin/perl
  2.  
  3. use strict;
  4. use DBI();
  5. use CGI;
  6. use CGI::Session(' ip_match ');
  7.  
  8.  
  9. my $session;
  10.  
  11. my $cgi = new CGI;
  12. $session = CGI::Session->load();
  13.  
  14. my $mmloption = $cgi->param('mmloption');
  15.  
  16.  
  17. if($session->is_expired)
  18.   {
  19.       print $cgi->header(-cache_control=>"no-cache, no-store, must-revalidate");
  20.       print "<p>Your has session expired. Please login again.<p></br>";
  21.       print "<a href='http://localhost//cgi-bin//mml%20log//login.pl'>Login</a>";
  22.   }
  23.   elsif ($session->is_empty)
  24.   {
  25.  
  26.       print $cgi->header(-cache_control=>"no-cache, no-store, must-revalidate");
  27.       print "You have not logged in";
  28.   }
  29.   else
  30.   {
  31.  
  32.  
  33. if ($mmloption eq "1")
  34. {
  35.     print $cgi->header(-type=>"text/html",-location=>"http://localhost//cgi-bin//mml%20log//1//optionA.pl");
  36. }
  37. elsif ($mmloption eq "12") 
  38. {
  39.  
  40.     print $cgi->header(-type=>"text/html",-location=>"http://localhost//cgi-bin//mml%20log//12//optionA.pl");
  41. }
  42. elsif ($mmloption eq "123")
  43. {
  44.     print $cgi->header(-type=>"text/html",-location=>"http://localhost//cgi-bin//mml%20log//123//optionA.pl");
  45. }
  46.  
  47. elsif ($mmloption eq "1234")
  48. {
  49.     print $cgi->header(-type=>"text/html",-location=>"http://localhost//cgi-bin//mml%20log//1234//optionA.pl");
  50. }
  51. else
  52. {
  53.  
  54.  
  55.  
  56. print
  57.     $cgi->header,
  58.     $cgi->start_html(-title=>'Elements Selection');
  59.  
  60. print <<HTML;
  61.  
  62. <FORM METHOD="GET">
  63. <div style="height100%; width100%; z-index:-1; position:absolute; top:0px; bottom:0px">
  64. <IMG SRC="C:\\Program Files\\Apache Software Foundation\\Apache2.2\\
  65.                         htdocs\\starhub1024by768.jpg" ALT="starhub">
  66. </div>
  67. <div style="position:absolute; top:223px"> 
  68. <p>Please Select the elements below:</p>
  69. <INPUT TYPE=RADIO NAME="mmloption" VALUE="12">12<BR></br>
  70. <INPUT TYPE=RADIO NAME="mmloption" VALUE="1">1<BR></br>
  71.  
  72. <input type=submit name=Query3 value=Submit>
  73. <a href='http://localhost//cgi-bin//mml%20log//login.pl?action=logout'>Logout</a>
  74. </div>
  75.  
  76. HTML
  77.  
  78. print $cgi->end_html();
  79. }
  80. }
  81.  
hopefully i did it correctly
Jun 6 '08 #4
numberwhun
3,509 Expert Mod 2GB
In your original post, you said you set the expiration to 1 minute. I looked through what you posted and I don't see it. I don't see where you used the expire() function to set the 1 minute time-out.

Regards,

Jeff
Jun 6 '08 #5
poolboi
170 100+
opps sorry

Expand|Select|Wrap|Line Numbers
  1. #!/perl/bin/perl
  2.  
  3. use strict;
  4. use DBI();
  5. use CGI;
  6. use CGI::Session(' ip_match ');
  7. use Digest::SHA1 qw(sha1);
  8.  
  9. my ($dbh, $sth, $name1, $name2, $session);
  10.  
  11. my $cgi = new CGI;
  12.  
  13. my $username = $cgi->param('username');
  14. my $password = $cgi->param('password');
  15.  
  16. if($username ne '')
  17. {
  18. $dbh = DBI->connect("DBI:mysql:database=authentication;host=localhost","##username##","##password##", 
  19.               {RaiseError => 1});
  20.  
  21. $sth = $dbh ->prepare("SELECT * FROM `example` WHERE Username='$username' AND Password=SHA1('$password')");
  22. $sth->execute();
  23. while (my $ref =$sth->fetchrow_hashref()) {
  24. $name1 = $ref->{'Username'}, $name2 = $ref->{'Password'};}
  25.  
  26.  
  27.  
  28. if ($username eq $name1 && ($username))
  29.     {
  30.        $session = new CGI::Session();
  31.         $session->expire("1m");
  32.        print $session->header(-location=> "http://localhost//cgi-bin//mml%20log//element_select.pl");
  33.     }
  34.     else
  35.     {
  36.     print
  37.     $cgi->header,
  38.     $cgi->start_html(-title=>'StarHub Login');
  39.  
  40. print <<HTML;
  41. <FORM METHOD="GET">
  42. <div style="height100%; width100%; z-index:-1; position:absolute; top:0px; bottom:0px">
  43. <IMG SRC="C:\\Program Files\\Apache Software Foundation\\Apache2.2\\
  44.                         htdocs\\starhub1024by768.jpg" ALT="starhub">
  45. </div>
  46. <div style="position:absolute; top:223px"> 
  47. <p>You have Entered an Incorrect password or username</p>
  48. <p>Please Log in below:</p>
  49. <p>Username: <INPUT TYPE=TEXT NAME="username"></p>
  50. <p>Password: <INPUT TYPE=PASSWORD NAME="password"></p></br>
  51. <INPUT TYPE=SUBMIT name=QUERY2 value="Log In"> 
  52. <a href="http://localhost//cgi-bin//mml%20log//passwordchange.pl">Forget your Password?</a>
  53. </div>
  54. </FORM>
  55. HTML
  56.  
  57. print $cgi->end_html();
  58.  
  59.     }
  60. $dbh->disconnect();
  61.  
  62. }
  63. elsif($cgi->param('action') eq 'logout')
  64.      {
  65.      $session = CGI::Session->load() or die CGI::Session->errstr;
  66.          $session->delete();
  67.          print $session->header(-location=>"http://localhost//cgi-bin//mml%20log//login.pl");
  68.      }
  69.      else
  70.      {  
  71.  
  72. print
  73.     $cgi->header,
  74.     $cgi->start_html(-title=>'StarHub Login');
  75.  
  76. print <<HTML;
  77. <FORM METHOD="GET">
  78. <div style="height100%; width100%; z-index:-1; position:absolute; top:0px; bottom:0px">
  79. <IMG SRC="C:\\Program Files\\Apache Software Foundation\\Apache2.2\\
  80.                         htdocs\\starhub1024by768.jpg" ALT="starhub">
  81. </div>
  82. <div style="position:absolute; top:223px"> 
  83. <p>Please Log in below:</p>
  84. <p>Username: <INPUT TYPE=TEXT NAME="username"></p>
  85. <p>Password: <INPUT TYPE=PASSWORD NAME="password"></p></br>
  86. <INPUT TYPE=SUBMIT name=QUERY2 value="Log In"> 
  87. </div>
  88. </FORM>
  89. HTML
  90.  
  91. print $cgi->end_html();
  92. }
  93.  
  94.  
sorry i added it in
i tried with that but it still didn;t work
Jun 6 '08 #6
numberwhun
3,509 Expert Mod 2GB
Unfortunately, I don't know why its not working then. The use would seem correct, but I just don't know. Wish I could help more, sorry.

Regards,

Jeff
Jun 6 '08 #7
poolboi
170 100+
hm...all i know is if a session expires
the session is deleted and becomes empty
perhaps that;s why it always detect it is an empty session
i've read some issues on this, apparently it's said to be a bug in the module
but no proven evidence yet
Jun 6 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: David Frauzel | last post by:
I'm writing a rough draft of a suite of small Perl apps that will, combined, serve as a web site's user sign-up, login, management, and customized content engine. I'm having trouble with the...
0
by: David Staschover | last post by:
I'm trying to set up sessions in perl. The session is initialized fine in session1.cgi In session2.cgi, the correct session id is returned from the cookie, but when I initialize the session, a...
5
by: Sullivan WxPyQtKinter | last post by:
Python disappointly failed to provide a convinient cgi session management module. Not willing to use external modules, I would like to implement a simplest Session object on my own. The basic...
14
by: ccdetail | last post by:
http://www.tiobe.com/index.htm?tiobe_index Python is the 7th most commonly used language, up from 8th. The only one gaining ground besides VB in the top 10. We're glad, our app is written in...
4
rajiv07
by: rajiv07 | last post by:
use CGI; use DBI; use CGI::Session; use CGI::Cookie; use CGI::Carp qw(fatalsToBrowser); my $q = new CGI; my $c = new CGI::Cookie;
0
by: Lastknight | last post by:
hi all I am trying to build a user authentication page for my project..i am getting message im the output as u r sessiion id is...... and it will expires on so....so ..time but when iam using that...
4
rajiv07
by: rajiv07 | last post by:
I have some problem in session loading use CGI; use CGI::Session; use CGI::Cookie; my $session = "" ; my $sid = "" ;
2
rajiv07
by: rajiv07 | last post by:
Hi to all I have a script to get geo IP which is successfully running on Linux server.but when i run this script on windows server it gives some header error #!C:/Perl/bin/perl.exe use CGI...
0
by: d0353101 | last post by:
I am having login.cgi. user enter id and password. if ok it redirects to main.cgi with user_id as main_page.cgi?user_id=$user_id. main.cgi is having left menu and right part is for doing some...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.