thanks..
i've actually found a workable code
right this code is for logging in
-
#!/perl/bin/perl
-
-
use CGI;
-
use CGI::Session (' ip_match ');
-
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
-
-
$q = new CGI;
-
-
$usr = $q->param('usr');
-
$pwd = $q->param('pwd');
-
-
if ($usr ne '')
-
{
-
if($usr eq "demo" and $pwd eq "demo")
-
{
-
$session = new CGI::Session();
-
print $session->header(-location=>'index.pl');
-
}
-
else
-
{
-
print $q->header(-type=>"text/html",-location=>"login.pl");
-
}
-
}
-
elsif($q->param('action') eq 'logout')
-
{
-
$session = CGI::Session->load() or die CGI::Session->errstr;
-
$session->delete();
-
print $session->header(-location=>'login.pl');
-
}
-
else
-
{
-
print $q->header;
-
print <<HTML;
-
<form method="post">
-
Username: <input type="text" name="usr">
-
-
Password: <input type="password" name="pwd">
-
-
-
<input type="submit">
-
and the other is for validating at the top of each cgi script
-
#!/perl/bin/perl
-
-
# index.pl
-
use CGI;
-
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
-
use CGI::Session ( '-ip_match' );
-
-
$session = CGI::Session->load();
-
$q = new CGI;
-
-
if($session->is_expired)
-
{
-
print $q->header(-cache_control=>"no-cache, no-store, must-revalidate");
-
print "Your has session expired. Please login again.";
-
print "<br/><a href='text.pl>Login</a>";
-
}
-
elsif($session->is_empty)
-
{
-
print $q->header(-cache_control=>"no-cache, no-store, must-revalidate");
-
print "You have not logged in";
-
}
-
else
-
{
-
print $q->header(-cache_control=>"no-cache, no-store, must-revalidate");
-
print "<h2>Welcome";
-
print "<a href='test.pl?action=logout'>Logout";
-
}
-
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?