Vahid
Try the following short script to test. If everything goes well, you should
see a persistent session id, and a counter which should increment each time
the page is revisited or refreshed (see
http://author.handalak.com/cgi-bin/session ). If it doesn't, there really is
a problem and we'll work on it.
P.S. You would discover this eventually, but you should look into
CGI::Application and HTML::Template (Or Template Toolkit). The way you're
doing things right now (with if/else, and embedded 'HTML'), you can only go
so far.
#!/usr/bin/perl -w
use strict;
use CGI;
use CGI::Carp ('fatalsToBrowser');
use CGI::Session;
my $query = CGI->new();
my $session = CGI::Session->new(undef, undef, {Directory=>'/tmp'});
my $counter = $session->param('counter') || 0;
$session->param('counter', ++$counter);
my $cookie = $query->cookie(-name=>$session->name, -value=>$session->id,
-expires=>"+1h");
print $query->header(-cookie=>$cookie),
$query->start_html("CGI::Session - " . $session->VERSION),
$query->h1("Testing CGI::Session " . $session->VERSION),
$query->h2($session->name . " : " . $session->id),
$query->h3("Counter: $counter"),
$query->end_html();
If it works, there's a problem with your code.
> -----Original Message-----
> From:
> cgi-session-user-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@xxxxxxxxxxxxxxxx
> [mailto:cgi-session-user-admin-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@xxxxxxxxxxxxxxxx]
> On
> Behalf Of Vahid Hedayati
> Sent: Monday, September 12, 2005 11:26 AM
> To: cgi-session-user-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@xxxxxxxxxxxxxxxx
> Subject: [Cgi-session-user] CGI::Session does not seem to be
> working for me
> Importance: High
>
>
> CGI::Session version (3) / Perl v.5.8.6 : on FreeBSD 4.7
>
> I have been trying for many hours to get CGI::Session to work:
>
> Here is my outcome after many hours of online searching testing:
>
> Trying to run a cgi script which authenticates after step 1 and then
> runs specfic actions once authenticated..
>
> Here is the web results:
>
>
> _____+++++++
> Original Session ID is
> ++++
>
> Welcome vahid you are now logged in
>
> Global username = vahid ::: 8d257f413fab17680ea94a176b3d71a6Clik me
> <http://logmgr/cgi-bin/Provision2.cgi?act=vf>
>
> __________________Once clicked shows no STORED Session ID
> and no global
> username at the bottom has a new SESSION ID: -->
>
> ___+++++++
> Original Session ID is
> ++++
> Global username = ::: 6afdaa81cb7c88dc195e1aaab41adf59Clik me
> <http://logmgr/cgi-bin/Provision2.cgi?act=vf>
>
>
> Basically what ever i have tried i end up with new session ids..
>
>
> here is the code:
>
>
> This is the top of the script:
>
>
>
> if ($act eq '' ) {
> $cg = new CGI;
> $session = new CGI::Session(undef,undef,{Directory=>"/tmp/"});
> $cookie = $cg->cookie(CGISESSID => $session->id);
> print $cg->header( -cookie=>$cookie );
> $sid=$session->id;
> print "Session ID is $sid<br>";
> &startup();
> } else {
> $cg = new CGI;
> $sid=$cg->cookie("CGISESSID");
> print "_____$sid+++++++<br>";
> $session = new CGI::Session(undef,$sid,{Directory=>"/tmp/"});
> print "Original Session ID is $sid<br>";
> $sid = $session->id();
> print "++++$sid_____<br>";
> &$act;
> }
>
> sub startup {
>
> $value="logon2.htm";
> &do($value);
> }
>
>
>
> sub login {
> $username=$cgi->param(username);
> $pass=$cgi->param(pass);
> if (($pass eq '') || ($username eq '' ) ) {
> print "<hr size=3 width=100%>";
> print "Missing Fields please hit back and try again -
> process halted";
> print "<hr size=3 width=100%>";
> } else {
> my $result = $ldap->bind("uid=$username,$base", password=>$pass);
> if($result->is_error()){
> my $errorMessage = $result->error();
> print "$errorMessage";
> } else {
> $session->param( "user_name","$username" );
> print "<p class=td align=center>Welcome $username you are now
> logged in</p>";
> &vf;
> # print
> "<script>\nwindow.location.replace(\"/cgi-bin/$formname?act=vf
> \");\n</script>";
> }
> }
> }
>
> sub vf {
> #$gname= cookie($gusername);
> $gname = $session->param("user_name");
>
> print "Global username = $gname ::: $sid";
> print "<a href=/cgi-bin/Provision2.cgi?act=vf>Clik me</a>";
> }
>
>
>
>
>
> -------------------------------------------------------
> SF.Net email is Sponsored by the Better Software Conference & EXPO
> September 19-22, 2005 * San Francisco, CA * Development
> Lifecycle Practices
> Agile & Plan-Driven Development * Managing Projects & Teams *
> Testing & QA
> Security * Process Improvement & Measurement *
> http://www.sqe.com/bsce5sf
> _______________________________________________
> Cgi-session-user mailing list
> Cgi-session-user-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@xxxxxxxxxxxxxxxx
> https://lists.sourceforge.net/lists/listinfo/cgi-session-user
>
>
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
|