Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Session Problem in Perl

Reply
Thread Tools

Session Problem in Perl

 
 
Praki
Guest
Posts: n/a
 
      12-11-2007
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
 
Reply With Quote
 
 
 
 
Ron Bergin
Guest
Posts: n/a
 
      12-11-2007
On Dec 11, 7:55 am, Praki <(E-Mail Removed)> wrote:
> 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.
 
Reply With Quote
 
 
 
 
Praki
Guest
Posts: n/a
 
      12-12-2007
On Dec 12, 1:41 am, Ron Bergin <(E-Mail Removed)> wrote:
> On Dec 11, 7:55 am, Praki <(E-Mail Removed)> wrote:
>
>
>
> > 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.


thanks for your input its working fine ...
thanks...
Prakash
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 1.4 What are Perl 4, Perl 5, or Perl 6? PerlFAQ Server Perl Misc 0 01-23-2011 05:00 AM
Session Timeout problems-web.confg session state and IIS session s =?Utf-8?B?Um9iSEs=?= ASP .Net 4 04-11-2007 04:52 PM
Session State - What does it take to establish one single ASP.NET session per "browser session" Jeff Smythe ASP .Net 3 01-02-2004 04:10 AM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM
How can I "know" the difference between a session timed out and a session that did session.abort? Jazzis ASP General 2 09-23-2003 07:16 AM



Advertisments