473,769 Members | 6,203 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

confusion over is_expired and is_empty in CGI:Session

170 New Member
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 2708
eWish
971 Recognized Expert Contributor
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 Recognized Expert Moderator Specialist
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 New Member
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 Recognized Expert Moderator Specialist
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 New Member
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 Recognized Expert Moderator Specialist
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 New Member
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
5474
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 concept of one particular part of the "application" (as it were) - session tracking. Perl itself is handling user authentication (since I've no idea how Perl could "ask" the server who just authenticated to htaccess), so the login script will have an...
0
5414
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 new session is created. The original and new session id don't match. Any help would be appreciated!
5
5685
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 problem is: how could a python CGI program understand several requests are in the same session? Definately, request from different IP would be easy to identified to be in different sessions, but request from the same IP would not. Anyone has any...
14
2089
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 python. It's free at http://pnk.com and it is a web timesheet for project accounting
4
2071
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
1146
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 in my page it doesn't work..I know i am commiting errors but i cant found exactly what is that..can somebody help me out to rectify this problem... #!/usr/bin/perl print"content-type:text/html\n\n"; use CGI::Session; $session = new...
4
3767
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
1983
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 qw/:standard/; use LWP::UserAgent; use HTTP::Request qw(GET POST); use HTTP::Headers;
0
1436
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 action. in all the CGI files including main.cgi I am writing this code before start_html to manage the session: --------------------------------------- my $cgi = CGI->new;
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7409
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.