Code Comments
Programming Forum and web based access to our favorite programming groups.I don't have much experience with Perl, so I'm sure the problem is probably
pretty obvious to many of you. But, when I run the following GCI script I
find the "if" tests on "loggedInCookie"/value and
"usernamePasswordPassedCookie"/value both pass the "if". But, the last "if"
shows that both "havelogin" and "haveusernameandpassword" are "false".
What's going on here?
Thanks for any help,
Don
.
.
.
# Check to see if client has logged in and passed Username/Password test.
#
my @cookiepairs=split(/;/, $ENV{'HTTP_COOKIE'});
my ($pair, $name, $value, %cookie);
my $havelogin = 'false';
my $haveusernameandpassword = 'false';
foreach $pair (@cookiepairs)
{
($name, $value) = split(/=/, $pair);
if($name == 'loggedInCookie' and $value == 'true')
{
$havelogin = 'true';
}
if($name == 'usernamePasswordPassedCookie' and $value == 'true')
{
$haveusernameandpassword = 'true';
}
}
if($havelogin == 'false' or $haveusernameandpassword == 'false')
{
# html code will go here stating user not logged in.
exit;
}
# Continue here if login is ok.
.
.
.
----== Posted via mcse.ms - Unlimited-Uncensored-Secure Usenet News==-
---
http://www.mcse.ms The #1 Newsgroup Service in the World! 120,000+ New
sgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Post Follow-up to this messageDon <no@adr.com> wrote: > I don't have much experience with Perl, so I'm sure the problem is > probably pretty obvious to many of you. But, when I run the following > GCI script I find the "if" tests on "loggedInCookie"/value and > "usernamePasswordPassedCookie"/value both pass the "if". But, the last > "if" shows that both "havelogin" and "haveusernameandpassword" are > "false". What's going on here? "==" compares it's arguments for numeric equality. You want "eq", which compares them for string equality. > if($havelogin == 'false' or $haveusernameandpassword == 'false') Xho -- -------------------- http://NewsReader.Com/ -------------------- Usenet Newsgroup Service $9.95/Month 30GB
Post Follow-up to this messageDon <no@adr.com> wrote: > I don't have much experience with Perl, so I'm sure the problem is probabl y > pretty obvious to many of you. But, when I run the following GCI script I > find the "if" tests on "loggedInCookie"/value and > "usernamePasswordPassedCookie"/value both pass the "if". But, the last "i f" > shows that both "havelogin" and "haveusernameandpassword" are "false". > What's going on here? If you had enabled warnings (as guidelines for this group specifically mention), the problem would have been made obvious. Hint: String comparisons and numeric comparisons do not use the same operator. Axel
Post Follow-up to this messageAxel wrote: > Don <no@adr.com> wrote: > > If you had enabled warnings (as guidelines for this group specifically > mention), the problem would have been made obvious. > > Hint: String comparisons and numeric comparisons do not use the same > operator. Is the OP going to: [1] enable warnings [2] change the comparison [3] both [4] neither :-D. -- John Small Perl scripts: http://johnbokma.com/perl/ Perl programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html
Post Follow-up to this messageDon wrote:
> # Check to see if client has logged in and passed Username/Password
> test. #
> my @cookiepairs=split(/;/, $ENV{'HTTP_COOKIE'});
> my ($pair, $name, $value, %cookie);
> my $havelogin = 'false';
> my $haveusernameandpassword = 'false';
The problem with string constants as used here is that a typo can
introduce behaviour that will take you quite some time to pin down.
> foreach $pair (@cookiepairs)
> {
> ($name, $value) = split(/=/, $pair);
> if($name == 'loggedInCookie' and $value == 'true')
> {
> $havelogin = 'true';
> }
> if($name == 'usernamePasswordPassedCookie' and $value ==
> 'true') {
> $haveusernameandpassword = 'true';
> }
> }
> if($havelogin == 'false' or $haveusernameandpassword == 'false')
> {
> # html code will go here stating user not logged in.
> exit;
> }
> # Continue here if login is ok.
This code gives me the creepy feeling that anyone setting
usernamePasswordPassedCookie to true is logged in...
--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Post Follow-up to this messageDon <no@adr.com> wrote: > I don't have much experience with Perl, Then you should ask for all the help you can get! > so I'm sure the problem is probably > pretty obvious to many of you. ^^^^^^ The problem is even obvious to a _machine_. If you ask it to, the machine will tell you where your problem is... > What's going on here? You aren't working smart. > if($name == 'loggedInCookie' and $value == 'true') You should always enable warnings when developing Perl code! -- Tad McClellan SGML consulting tadmc@augustmail.com Perl programming Fort Worth, Texas
Post Follow-up to this messageJohn Bokma <postmaster@castleamber.com> wrote: > Is the OP going to: > > [1] enable warnings > [2] change the comparison > [3] both > [4] neither Who knows? I am going to have a beer :) Axel
Post Follow-up to this messageOn Sun, 24 Apr 2005 01:54:02 -0500, Axel <axel@white-eagle.invalid.uk> wrote: >Don <no@adr.com> wrote: > >If you had enabled warnings (as guidelines for this group specifically >mention), the problem would have been made obvious. > >Hint: String comparisons and numeric comparisons do not use the same >operator. > >Axel I have "use warnings" at the top of the module. But, all I get is "500 server error" when I run the script on the server. I changed the operators as suggested, but still get that error message, and no warnings from Perl. Don ----== Posted via mcse.ms - Unlimited-Uncensored-Secure Usenet News==- --- http://www.mcse.ms The #1 Newsgroup Service in the World! 120,000+ New sgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Post Follow-up to this message*** post for FREE via your newsreader at post.newsfeed.com ***
(Please don't use "adr.com" if it doesn't belong to you.)
Don> # Check to see if client has logged in and passed Username/Password
test.
Don> #
Don> my @cookiepairs=split(/;/, $ENV{'HTTP_COOKIE'});
Please don't do this. Use CGI.pm, and the "cookie" method there.
Otherwise, you will incorrectly declare an encoded value of "%74rue"
to be false, even though technically it's true. (A browser could
choose to hexify every character of an incoming cookie at its
discretion.)
print "Just another Perl hacker,"; # the original!
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training
!
-----= Posted via Newsfeed.Com, Uncensored Usenet News =-----
http://www.newsfeed.com - The #1 Newsgroup Service in the World!
-----== 100,000 Groups! - 19 Servers! - Unlimited Download! =-----
Post Follow-up to this messageDon <no@adr.com> wrote: > I have "use warnings" at the top of the module. But, all I get is "500 > server error" when I run the script on the server. Did you look in your server logs? That is where STDERR goes for CGI programs. Did you try running your program from the command line rather than from the CGI environment? Have you read the answser to your Frequently Asked Question already? perldoc -q 500 My CGI script runs from the command line but not the browser. (500 Server Error) Have you checked out the Perl FAQs related to CGI programming with Perl? perldoc -q CGI Where can I learn about CGI or Web programming in Perl? How can I get better error messages from a CGI program? > I changed the operators as suggested, but still get that error message, an d > no warnings from Perl. Show the code. Show the messages. We are not very good mind readers... -- Tad McClellan SGML consulting tadmc@augustmail.com Perl programming Fort Worth, Texas
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.