Session Problem in Perl

P

Praki

Greetings All,

i m creating a session storing the loging credentials. i want to
access that data later after crossing two pages.i have created the
sesion but i could not get the data back some where i m going wrong
can u point me where ..

my first first file getting the login credentials

#!/usr/local/bin/perl5
&top();
&login_check();
&bottom();
sub top{
print <<EOM1;
Content-type: text/html


<html>
<head>
<title>Login Authentication</title>
</head>
<body>
EOM1
}
sub bottom{
print <<EOM2;
</body>
</html>
EOM2
}
sub login_check{
print <<EOM;
<h3>Enter the login Password</h3>
<form method="post" action="cookie.cgi">
<input type="hidden" name="username" value='Submit'>
<p>Username: <input type="text" name="uid" size="20"></p>
<p>Password: <input type="password" name="passwd" size="20"></p>
<input type="submit" value="Submit" name="submit">
</form>
EOM
}

second file where i m creating the session.

#!/usr/local/bin/perl5
use Net::LDAP;
&top();
&login_check();
&bottom();

sub top{
print <<EOM1;
Content-type: text/html


<html>
<head>
<title>Login Authentication</title>
</head>
<body>
EOM1
}
sub bottom{
print <<EOM2;
</body>
</html>
EOM2
}
sub login_check{
my ($ret);
use CGI;
my $query = new CGI;
$query->param("submit");
my $userid = $query->param("uid");
my $password = $query->param("passwd");
use CGI;
use CGI::Session;

$session = new CGI::Session("driver:File",undef,{'Directory'=>"/
tmp"});
$sid = $session->id();
print "Session id:".$sid;

#$session->name($userid);
# Write the session variable on the server
$session->param('username',$userid);
$session->param('password',$password);
print "username:".$userid."pass:";

$usernam = $session->param('username');
$passwor = $session->param('password');

print "username from the cookie:".$usernam;

#create session cookie
$cookie = $query->cookie(CGISESSID => $session->id);
print $query->header( -cookie=>$cookie );
#print "cookie:".$cookie;
print <<EOM;
<h5>Cookie created <a href="/cgi-bin/sesion/cookie/
test.cgi">click here to check</a> </h5>
EOM
}

Third file to access the session values.

#!/usr/local/bin/perl5
&top();
&cookie_check();
&bottom();
sub top{
print <<EOM1;
Content-type: text/html


<html>
<head>
<title>Login Authentication</title>
</head>
<body>
EOM1
}
sub bottom{
print <<EOM2;
</body>
</html>
EOM2
}
sub cookie_check{
use CGI;
use CGI::Session;
my $query = new CGI;

$sid = $query->cookie('CGISESSID') || $query->param('CGISESSID') ||
undef;
$session = new CGI::Session(undef, $sid, {Directory=>'/tmp'});
$username = $session->param('username');
$password = $session->param('password');

print <<EOM;
<h3>Cookie test $username $password</h3>
EOM
}

i m not getting the values when i read here. i dont know where the
cookie is created. i check with the server i could see the session
which is created in the server.please tell me where i m going
wrong.....

thanks in advance..
Prakash
 
R

Ron Bergin

Greetings All,

i m creating a session storing the loging credentials. i want to
access that data later after crossing two pages.i have created the
sesion but i could not get the data back some where i m going wrong
can u point me where ..

my first first file getting the login credentials

#!/usr/local/bin/perl5
&top();
&login_check();
&bottom();
sub top{
print <<EOM1;
Content-type: text/html

<html>
<head>
<title>Login Authentication</title>
</head>
<body>
EOM1}

sub bottom{
print <<EOM2;
</body>
</html>
EOM2}

sub login_check{
print <<EOM;
<h3>Enter the login Password</h3>
<form method="post" action="cookie.cgi">
<input type="hidden" name="username" value='Submit'>
<p>Username: <input type="text" name="uid" size="20"></p>
<p>Password: <input type="password" name="passwd" size="20"></p>
<input type="submit" value="Submit" name="submit">
</form>
EOM

}

second file where i m creating the session.

#!/usr/local/bin/perl5
use Net::LDAP;
&top();
&login_check();
&bottom();

sub top{
print <<EOM1;
Content-type: text/html

<html>
<head>
<title>Login Authentication</title>
</head>
<body>
EOM1}

sub bottom{
print <<EOM2;
</body>
</html>
EOM2}

sub login_check{
my ($ret);
use CGI;
my $query = new CGI;
$query->param("submit");
my $userid = $query->param("uid");
my $password = $query->param("passwd");
use CGI;
use CGI::Session;

$session = new CGI::Session("driver:File",undef,{'Directory'=>"/
tmp"});
$sid = $session->id();
print "Session id:".$sid;

#$session->name($userid);
# Write the session variable on the server
$session->param('username',$userid);
$session->param('password',$password);
print "username:".$userid."pass:";

$usernam = $session->param('username');
$passwor = $session->param('password');

print "username from the cookie:".$usernam;

#create session cookie
$cookie = $query->cookie(CGISESSID => $session->id);
print $query->header( -cookie=>$cookie );
#print "cookie:".$cookie;
print <<EOM;
<h5>Cookie created <a href="/cgi-bin/sesion/cookie/
test.cgi">click here to check</a> </h5>
EOM

}

Third file to access the session values.

#!/usr/local/bin/perl5
&top();
&cookie_check();
&bottom();
sub top{
print <<EOM1;
Content-type: text/html

<html>
<head>
<title>Login Authentication</title>
</head>
<body>
EOM1}

sub bottom{
print <<EOM2;
</body>
</html>
EOM2}

sub cookie_check{
use CGI;
use CGI::Session;
my $query = new CGI;

$sid = $query->cookie('CGISESSID') || $query->param('CGISESSID') ||
undef;
$session = new CGI::Session(undef, $sid, {Directory=>'/tmp'});
$username = $session->param('username');
$password = $session->param('password');

print <<EOM;
<h3>Cookie test $username $password</h3>
EOM

}

i m not getting the values when i read here. i dont know where the
cookie is created. i check with the server i could see the session
which is created in the server.please tell me where i m going
wrong.....

thanks in advance..
Prakash

There are a number of issues that should be addressed, but the main
issue is in cookie.cgi. Your &top sub is outputting headers without
the session cookie and then &login_check tries to output the headers
again, this time with the session cookie, but it's too late. You can
only send the header once.
 
P

Praki

There are a number of issues that should be addressed, but the main
issue is in cookie.cgi. Your &top sub is outputting headers without
the session cookie and then &login_check tries to output the headers
again, this time with the session cookie, but it's too late. You can
only send the header once.

thanks for your input its working fine ...
thanks...
Prakash
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top