I'm creating my own module to handle sessions and other stuff for my site:
<code> package Skyline;
use Apache::DBI; use Apache::Cookie; use Exporter;
@ISA = ('Exporter'); @EXPORT_OK = ('check_login', 'init_db', '$dbh'); @EXPORT = ('check_login', 'init_db', '$dbh'); our $dbh;
sub check_login {
my %cookies = Apache::Cookie->fetch;
return ($cookies{uid}->value, $cookies{ut}->value, $cookies{sid}->value, $cookies{rnd1}->value);
}
sub init_db {
$dbh = DBI->connect("DBI:mysql:database=skyline;host=192.168.254.25", "root", "linux", {'RaiseError' => 1});
}
1; </code>
In order to test my code, I've written another little test script:
<code> #!/usr/bin/perl
use CGI; use Skyline;
my $cgi = new CGI;
my ($uid, $ut, $sid, $rnd1) = check_login();
print $cgi->header;
print "<html><body>sid = $sid, rnd = $rnd1, uid = $uid, ut = $ut</body></html>";
</code>
which give me 'sid = Apache::Cookie=SCALAR(0x872a958), rnd = , uid = Apache::Cookie=SCALAR(0x86b1ce0), ut = Apache::Cookie=SCALAR(0x86c0874)' or a variation with different scalar addresses. What am I doing wrong? I know the cookies exist. I wrote another test script:
So how do you set rnd? I am assuming that is what you are asking about, though the question "What am I doing wrong?" is difficult to answer if we don't know what you are *trying* to do. Have you checked the expiration date of the cookie, and if it has a domain/path restriction? I don't see anything in your code specifically, other than the absence of strict and warnings naturally.
<code> #!/usr/bin/perl
use CGI; use Apache::Cookie;
my $cgi = new CGI; my %cookies = Apache::Cookie->fetch;
print $cgi->header; foreach (keys %cookies) { $cval = $cookies{$_}->value; print "$_ = $cval<p>"; } </code>
This outputs all 4 cookies and their values. Anyone have any idea what I'm doing wrong?
I assume you aren't calling this the second time after calling a script that sets the cookies. Have you tried adding an exists or definedness in the 'check_login' function to make sure the cookie really is in the hash? How about printing all of your cookies from there?
http://danconia.org
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>