473,395 Members | 1,677 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,395 software developers and data experts.

how session tracking is done in perl?

170 100+
hey guys,

i've done most of my web app. for searching almost done
but then i got a small little problem with logging in
i need to know how session tracking is done in perl
if not my log in page would truely be redundant
May 29 '08 #1
2 3358
numberwhun
3,509 Expert Mod 2GB
hey guys,

i've done most of my web app. for searching almost done
but then i got a small little problem with logging in
i need to know how session tracking is done in perl
if not my log in page would truely be redundant
Well, to manage the session you could use the CGI::Session Perl module.

Regards,

Jeff
May 29 '08 #2
poolboi
170 100+
thanks..
i've actually found a workable code

right this code is for logging in
Expand|Select|Wrap|Line Numbers
  1. #!/perl/bin/perl
  2.  
  3. use CGI;
  4. use CGI::Session (' ip_match ');
  5.  use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
  6.  
  7. $q = new CGI;
  8.  
  9. $usr = $q->param('usr');
  10. $pwd = $q->param('pwd');
  11.  
  12. if ($usr ne '')
  13. {
  14. if($usr eq "demo" and $pwd eq "demo")
  15.       {
  16.           $session = new CGI::Session();
  17.           print $session->header(-location=>'index.pl');
  18.       }
  19.        else
  20.       {
  21.           print $q->header(-type=>"text/html",-location=>"login.pl");
  22.       }
  23. }
  24. elsif($q->param('action') eq 'logout')
  25.   {
  26.       $session = CGI::Session->load() or die CGI::Session->errstr;
  27.       $session->delete();
  28.       print $session->header(-location=>'login.pl');
  29.   }
  30.   else
  31.   {
  32.     print $q->header;
  33. print <<HTML;
  34.  <form method="post">
  35.           Username: <input type="text" name="usr">
  36.  
  37.           Password: <input type="password" name="pwd">
  38.  
  39.  
  40.           <input type="submit">
  41.  
and the other is for validating at the top of each cgi script
Expand|Select|Wrap|Line Numbers
  1. #!/perl/bin/perl
  2.  
  3.   # index.pl
  4.   use CGI;
  5.   use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
  6.   use CGI::Session ( '-ip_match' );
  7.  
  8.   $session = CGI::Session->load();
  9.   $q = new CGI;
  10.  
  11.   if($session->is_expired)
  12.   {
  13.       print $q->header(-cache_control=>"no-cache, no-store, must-revalidate");
  14.       print "Your has session expired. Please login again.";
  15.  print "<br/><a href='text.pl>Login</a>";
  16.   }
  17.   elsif($session->is_empty)
  18.   {
  19.       print $q->header(-cache_control=>"no-cache, no-store, must-revalidate");
  20.       print "You have not logged in";
  21.   }
  22.   else
  23.   {
  24.       print $q->header(-cache_control=>"no-cache, no-store, must-revalidate");
  25.       print "<h2>Welcome";
  26.       print "<a href='test.pl?action=logout'>Logout";
  27.   }
  28.  
i'm just wondering
i i were to write the validation code at the top each time..
it's so troublesome
is there any way i can call this script or anything
so that i dun have to always repeat the whole chunk of code?
May 30 '08 #3

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

Similar topics

4
by: Celebrate | last post by:
I'm noticing that when my homepage first starts up, all the menu links to other pages have the session info appended to the URL. For example: ...
1
by: marslee | last post by:
I am a php newbie. I would like to count how many times a user visit a webpage. I know session tracking should be used, but where i put the code? Is it inside the html that the user visit? ...
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...
6
by: Patrick Olurotimi Ige | last post by:
I'm tracking usersOnline by adding this code below in my Global.asax file.But i noticed that when a user logs in it keeps adding a new user which thats fine..but when a user logs of it still...
2
by: Jan | last post by:
In a 2-page order form, not all applicants will complete it due to field validations. If I want to see data from incomplete orders, can this be done using some sort of session control so that each...
2
by: runner7 | last post by:
Can anyone tell me if there is a way in PHP to determine when a session times out on the server or how many concurrent sessions there are in your application?
6
by: Scubadude | last post by:
Hi, I'm new to perl and have run into some roadblocks while trying to run tutorials. I have installed Apache v2.2.3 I have installed ActivePerl v6.6.1.638 I have installed php v5.2.0 I am...
43
by: davidkoree | last post by:
I mean not about cookie. Does it have something to do with operating system or browser plugin? I appreciate any help.
3
by: Charles Abetz | last post by:
Hi all My problem is that I am creating a session file on the server when the user first visits my website, but when the user logs in i want to write to the file again with the timestamp and their...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.