I tried the following on the command line:
echo $ENV{HTTP_Cookie}
/local/home/mk_murex/.kshrc{HTTP_Cookie}
echo $ENV{HTTP_COOKIE}
/local/home/mk_murex/.kshrc{HTTP_COOKIE}
However, in .kshrc, there is no entry as
HTTP_Cookie or HTTP_COOKIE.
If I were to add the line
export HTTP_Cookie=[x]
in .kshrc, what is the correct value for HTTP_Cookie?
(Or should I add export HTTP_COOKIE instead?)
...
I agree. I now need to know how to set the cookie in .kshrc.
It looks like you do not have the faintest idea how CGI and cookies
work. I would recommend that you stop for a little bit, and figure that
stuff (which is off-topic) out first.
Write a simple script that tries to set a cookie, and another one that
attempts to retrieve it. Play with your browser's cookie settings to see
what happens. Etc etc.
I have successfully set the cookie MXRT_USERACL to contain the following
information:
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&MacroList&%5BAEP_MACROS%5D&Lists&1&EditPnL&%5B%5D&BO&&Password&XEdq1YTUaOFwo&Logs&1&Eod&1;
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 protected]
Servers=1
PnL=[]
Group=BO
MacroList=[AEP_MACROS]
Lists=1
I am getting the following error message when I clicked on the weblink
that in turn run the perl script test.pl:
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator,
(e-mail address removed) and inform them of the time the error
occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error
log.
--------------------------------------------------------------------------------
Apache/1.3.31 Server at [servername] Port 80
Source code for the web link, which calls test.pl:
<li><img src=../images/mnuspc.gif><a
href="/cgi/upload_repo/test.pl">Upload Repos</a></li>
When I clicked on the link, the link calls test.pl.
Source code for test.pl as follows:
#!/usr/bin/perl -w
use strict;
use CGI;
require "./mxrt_auth.pl";
# $query stores a CGI object
my $query = new CGI;
# %USERACL has 0 items because mxrt_auth.pl::initAuthMgr returns an empty
cookie
# i.e. the list of cookie names for AUTHQ is empty
my %USERACL = initAuthMgr($query); # see the next part of my post
# supposed to print contents of %USERACL, but prints nothing
while ( (my $key, my $value) = each %USERACL) {
print "$key = $value\n";
}
1;
now the source code for mxrt_auth.pl::initAuthMgr:
#!/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;
#-------------------------------------------------------------------------------
# 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
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;
}
I was previously asked how the cookie MXRT_USERACL was set. Here is how -
when the user logs in to my homepage, the following subroutine was called,
which set the cookie MXRT_USERACL:
sub tryLogin {
my $userid = uc $query->param('userid');
$USERID=$userid;
my $password = encrypt_password($query->param('pass1'));
my $user_info = ();
# setup empty cookie in case we return without success.
$COOKIE = $query->cookie(-name=>'MXRT_USERACL',
-value=>$user_info,
-expires=>'+1d');
if ($userid eq "") {
return "";
}
if (!$userid && !$password) {
return "Please enter USERID and PASSWORD.";
}
if (! exists $USERS{$userid}) {
return "Invalid USERID ($userid). Please try again.";
}
if ($USERS{$userid}{Password} ne $password) {
return "Invalid PASSWORD. Please try again.";
}
#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 "";
}
Now after the successful login, the cookie MXRT_USERACL was set.
I got the error message (as quoted above)
when I clicked on the following link as I described above.
Source code for the web link:
<li><img src=../images/mnuspc.gif><a
href="/cgi/upload_repo/test.pl">Upload Repos</a></li>
My question: why the error message?
and what is the fix?