Hey all;
I have been using sessions for some time now, but for some reason they are not working all of a sudden. Below is a copy of my code, please help me try and find out why?
Here is the script that starts the session:
Here is the script that "continues" the session:
If I print out $sid, it is blank, which means I can't get any session variables, so for some reason this means the cookie isn't being retreived properly.
Any and all help is GREATLY appreciated.
Sean.
I have been using sessions for some time now, but for some reason they are not working all of a sudden. Below is a copy of my code, please help me try and find out why?
Here is the script that starts the session:
Code:
#!/usr/bin/suidperl -U
use CGI;
use CGI::Session;
my $cgi = new CGI;
$username = $cgi->param('username');
$password = $cgi->param('password');
my $session = new CGI::Session(undef, undef, {Directory=>'/tmp'});
$session->expire('+30m');
$cookie = $cgi->cookie(CGISESSID => $session->id);
print $cgi->header( -cookie=>$cookie );
if((!$username) || (!$password)){
printForm();
}
else{
$session->param('username', "$username");
($name,$passwd,$uid,$gid,$quota,$comment,$gcos,$dir,$shell) = getpwnam("$username");
$< = $uid;
$realpass = (getpwuid($<))[1];
die "Unsuccessful!" unless(crypt($password,$realpass) eq $realpass);
print <<EOHTML;
Content-type: text/html\n\n
<HTML>
<script language="JavaScript">
<!--
function redirectPage() {
window.top.location='test.cgi';
}
-->
</script>
<BODY onLoad="redirectPage();">
<CENTER><H2>Please Wait While Loading...</H2></CENTER>
</BODY>
</HTML>
EOHTML
}
sub printForm(){
print <<EOHTML;
<table cellspacing="2">
<tr><td colspan="2">Please Enter Your Cadmin Username and Password</td></tr>
<form name="login_form" method="post" action="login.cgi">
<tr><td>
Username
</td><td>
<input type="text" name="username">
</td></tr>
<tr><td>
Password
</td><td>
<input type="password" name="password">
</td><tr>
<tr><td colspan="2"><input type="submit" name="submit" value="Login"></td></tr>
</form>
</table>
EOHTML
}
Here is the script that "continues" the session:
Code:
#!/usr/bin/perl
use CGI;
use CGI::Session;
$cgi = new CGI;
$sid = $cgi->cookie("CGISESSID");
$session = new CGI::Session(undef, $sid, {Directory=>'/tmp'});
my $username = $session->param('username');
print "Content-type: text/html\n\n";
if (!$username){
print <<EOHTML;
<HTML>
<BODY>
sid = $sid <BR>
Username = $username <BR>
cgi = $cgi <BR>
<CENTER><H2>Please Wait While Loading...</H2></CENTER>
</BODY>
</HTML>
EOHTML
}
If I print out $sid, it is blank, which means I can't get any session variables, so for some reason this means the cookie isn't being retreived properly.
Any and all help is GREATLY appreciated.
Sean.