Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple CGI Question

Status
Not open for further replies.

demejanos

Programmer
Jun 12, 2008
7
HU
Hello!

I've made a simple login page in perl/cgi (CGI and CGI:Session), and I have a file which I'd like to reach only from authenticated users.

My problem is that I can't reach $cgi variable and the $session variable from the 2nd file, which I'd like to restrict.

I'm not using any packages yet.

Thanks for any help!
 
If you are tyring to pass $cgi and $session, that's exactly what you need to do "Pass them" via something like a cookie or a hidden field.

The documentation for CGI and CGI::Session on CPAN, will show you how this is done.
 
OK, I've tried it.
I choose the cookie method for storing the session id.

But somehow, in the protected file I can't read the cookie.
Here are parts of the code:

login.cgi
...
our $cgi = new CGI;
our $session = new CGI::Session("driver:MySQL;id:MD5", undef, {Handle=>$dbh});
our $cookie = $cgi->cookie(CGISESSID => $session->id );

print $cgi->header(-type=>'text/html',-charset=>'UTF-8', -cookie=>$cookie, -target=>'main' ) . $cgi->start_html(-title=>'Tokenizer');
...
$session->param(-name=>'logged-in', -value=>'1');
...

index.cgi (protected file)
...
our $cgi = new CGI;
our $sid = $cgi->cookie("CGISESSID") || undef;
our $session = new CGI::Session("driver:MySQL;id:MD5", $sid, {Handle=>$dbh2});
...

Here, the $sid variable becomes undef, after a successful login.
 
Sorry, it's working, the problem belongs to the session part.
I can store and retrive the cookie, but the session doesn't get into the MySQL table, and I can't read ans store session variables.
 
Sorry for the inconvinience, it's working with a newer version of CGI and CGI::Session.

There was some bug in the ubuntu version.

Thanks for the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top