Re: %USERACL Is Empty?!
- From: William <wh2leung@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 12 Dec 2005 18:32:00 -0500
J. Gleixner wrote:
> You need to print the HTTP header before you print anything.
>
> > # $query stores a CGI object
> > my $query = new CGI;
>
> print $query->header;
I have added "print $query->header;" in test.pl as follows:
#!/usr/bin/perl -w
use strict;
use CGI;
require "./mxrt_auth.pl";
my $query = new CGI;
# %USERACL has 0 items because initAuthMgr returns an empty cookie
# i.e. the list of cookie names for AUTHQ is empty
my %USERACL = initAuthMgr($query); # see below
print $query->header;
print "is admin: $USERACL{IsAdmin}\n"; # prints "is admin:"
while ( (my $key, my $value) = each %USERACL) {
print "$key = $value\n";
}
Once again, mxrt_auth.pl is as follows:
#!/usr/bin/perl -w
require "./mxrt_vars.pl";
# we need this because perl CGI reference the environment variable
HTTP_COOKIE
# but vqsvr set the variable HTTP_Cookie (note the case!)
$ENV{'HTTP_COOKIE'}=$ENV{'HTTP_Cookie'};
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use Time::Local;
my $AUTHQ;
my %AUTH_INFO;
1;
#-------------------------------------------------------------------------------
# Sub-routines
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# This function retuns the cookie for this session (hash format)
#-------------------------------------------------------------------------------
sub initAuthMgr {
($AUTHQ) = @_;
# need to pick up the cookie 'MXRT_USERACL' to fill the hash
%AUTH_INFO
%AUTH_INFO = $AUTHQ->cookie('MXRT_USERACL');
my $num_keys = keys %AUTH_INFO;
# print "$num_keys\n"; # problem found - %AUTH_INFO has 0 keys
print $AUTHQ->header;
my @cookies = $AUTHQ->cookie();
my $num_cookies = @cookies;
print "number of cookies: $num_cookies\n";
foreach my $cookie ( @cookies ) {
print "current cookie: $cookie\n";
}
foreach (keys %AUTH_INFO) {
print $AUTH_INFO{$_}."<br>";
}
return %AUTH_INFO;
}
Output I got from running test.pl:
number of cookies: 0 Content-Type: text/html is admin:
It is apparent that %USERACL is empty. But when the user logs in, I have
set the cookie MXRT_USERACL to the following:
HTTP_COOKIE=LOGGED OUT; MXRT_USERACL=LOGGED%20OUT
COOKIE:
MXRT_USERACL=Name&william%20Leung&Status&1&Macros&1&IsAdmin&1&FileMgr&1&LoginID&LEUNGW5&Email&william.leung%40uwaterloo.com&PnL&%5B%5D&Servers&1&Group&BO&Ma$
path=/cgi/; expires=Tue, 13-Dec-2005 21:00:44 GMT
USERACL...
>>>> EditPnL=[]
>>>> BO=
>>>> Name=william Leung
>>>> Password=XEdq1YTUaOFwo
>>>> Status=1
>>>> Logs=1
>>>> IsAdmin=1
>>>> Macros=1
>>>> LoginID=LEUNGW5
>>>> FileMgr=1
>>>> Eod=1
>>>> Email=william.leung@xxxxxxxxxxxxx
>>>> Servers=1
>>>> PnL=[]
>>>> Group=BO
>>>> MacroList=[AEP_MACROS]
>>>> Lists=1
Note that IsAdmin=1, therefore $USERACL{IsAdmin} should print "1".
How the cookie was set:
when the user logs in to my homepage, the following subroutine was called,
which set the cookie MXRT_USERACL:
sub tryLogin {
// ....
#create the actual cookie
$user_info = $USERS{$userid};
$COOKIE = $query->cookie(-name=>'MXRT_USERACL',
-value=>$user_info,
-expires=>'+1d');
# notify that the login was successful and set the user ACL. We set
the
# user ACL because the one obtained from the original cookie may now
be out
# of date.
$ACTION="login_ok";
%USERACL = %$user_info;
authLog("Login successful", \%USERACL);
#authLog($query->cookie('MXRT_USERACL'), \%USERACL);
return "";
}
Going back to mxrt_auth.pl::initAuthMgr from the top of this reply, the
cookie was retrieved using the following:
%AUTH_INFO = $AUTHQ->cookie('MXRT_USERACL');
I then made the following method call in test.pl which (supposed to) pick
up the cookie MXRT_USERACL:
my $query = new CGI;
# %USERACL has 0 items because initAuthMgr returns an empty cookie
my %USERACL = initAuthMgr($query);
(%USERACL was set to the value of %AUTH_INFO)
Question: I already set the cookie MXRT_USERACL. Why is
$USERACL{IsAdmin} (and %USERACL, for that matter) empty?
.
- Follow-Ups:
- Re: %USERACL Is Empty?!
- From: A. Sinan Unur
- Re: %USERACL Is Empty?!
- References:
- %USERACL Is Empty?!
- From: William
- Re: %USERACL Is Empty?!
- From: xhoster
- Re: %USERACL Is Empty?!
- From: William
- Re: %USERACL Is Empty?!
- From: Paul Lalli
- Re: %USERACL Is Empty?!
- From: William
- Re: %USERACL Is Empty?!
- From: Paul Lalli
- Re: %USERACL Is Empty?!
- From: William
- Re: %USERACL Is Empty?!
- From: Paul Lalli
- Re: %USERACL Is Empty?!
- From: William
- Re: %USERACL Is Empty?!
- From: A. Sinan Unur
- Re: %USERACL Is Empty?!
- From: William
- Re: %USERACL Is Empty?!
- From: J. Gleixner
- %USERACL Is Empty?!
- Prev by Date: Re: What is the reason for Perl?
- Next by Date: using specific features in module XML::Simple
- Previous by thread: Re: %USERACL Is Empty?!
- Next by thread: Re: %USERACL Is Empty?!
- Index(es):
Relevant Pages
|