Dazz45X has asked for the wisdom of the Perl Monks concerning the following question:
Hello Perlmonks I have been incorporating a login system into my site, the scripts for the site are perhaps stretching back 15 years and include old code and new so some of it is cobbled together but it works. I have a login script that generates and sets a cookie and includes username, password and login value it also validates the user with the site database so if the user enters the correct data they will get the cookie, if not no cigar. This works correctly and places the cookie on the users machine and my server. The main script controls the rest of the site. My problem is this. I am using the following code at the start of the script
%cookies = CGI::Cookie->fetch; $sessionid = $cookies{'CGISESSID'}->value; $session = CGI::Session->load(undef, $sessionid, {Directory=>''}) + or die CGI:Session->errstr(); $login = $session->param('login'); $logswitch = ($login);
$logswitch is the variable to switch the username and password entry screens on and off (i.e. 1 and 0) With the above code when the user is logged in all works correctly, when the user is not logged in (ie no cookie) I get a 'Can't call method "value" on an undefined value' error. To negate this I have tried this code
if (exists $cookies{name}) { %cookies = CGI::Cookie->fetch; $sessionid = $cookies{'CGISESSID'}->value; $session = CGI::Session->load(undef, $sessionid, {Directory=>''} +) or die CGI::Session->errstr(); $login = $session->param('login'); $logswitch = ($login); }
This works well for a user with no cookie but if the user logs in, the value of $logswitch remains undef and so fails to trigger the click through screens. Any help would be appreciated as I have been on this for days now, I think I've read everything on CPAN and I use strict, warnings, diagnostics and anything else I can lay my hands on in all of my scripts. I may just be brain frazzled at the moment so apologies if it's obvious, just can't see it myself. Thank you in advance Dazz
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fetching cookies without errors?
by Corion (Patriarch) on Aug 23, 2017 at 12:36 UTC | |
by Dazz45X (Novice) on Aug 23, 2017 at 15:13 UTC | |
by hippo (Archbishop) on Aug 23, 2017 at 15:28 UTC | |
by Dazz45X (Novice) on Aug 23, 2017 at 15:46 UTC | |
|
Re: Fetching cookies without errors?
by poj (Abbot) on Aug 23, 2017 at 15:21 UTC | |
by Dazz45X (Novice) on Aug 23, 2017 at 15:37 UTC | |
by huck (Prior) on Aug 23, 2017 at 15:59 UTC | |
by afoken (Chancellor) on Aug 23, 2017 at 19:44 UTC | |
by Anonymous Monk on Aug 23, 2017 at 20:12 UTC | |
by Dazz45X (Novice) on Aug 23, 2017 at 17:27 UTC | |
by Anonymous Monk on Aug 23, 2017 at 19:29 UTC |