Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Why does variable value change?
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 =----

Report this thread to moderator Post Follow-up to this message
Old Post
Don
04-24-05 08:56 AM


Re: Why does variable value change?
Don <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

Report this thread to moderator Post Follow-up to this message
Old Post
xhoster@gmail.com
04-24-05 08:56 AM


Re: Why does variable value change?
Don <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


Report this thread to moderator Post Follow-up to this message
Old Post
Axel
04-24-05 01:56 PM


Re: Why does variable value change?
Axel 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


Report this thread to moderator Post Follow-up to this message
Old Post
John Bokma
04-24-05 01:56 PM


Re: Why does variable value change?
Don 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


Report this thread to moderator Post Follow-up to this message
Old Post
John Bokma
04-24-05 01:56 PM


Re: Why does variable value change?
Don <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

Report this thread to moderator Post Follow-up to this message
Old Post
Tad McClellan
04-24-05 01:56 PM


Re: Why does variable value change?
John 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


Report this thread to moderator Post Follow-up to this message
Old Post
Axel
04-24-05 01:56 PM


Re: Why does variable value change?
On 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 =----

Report this thread to moderator Post Follow-up to this message
Old Post
Don
04-24-05 08:56 PM


Re: Why does variable value change?
*** 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! =-----


Report this thread to moderator Post Follow-up to this message
Old Post
Randal L. Schwartz
04-24-05 08:56 PM


Re: Why does variable value change?
Don <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

Report this thread to moderator Post Follow-up to this message
Old Post
Tad McClellan
04-24-05 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

PERL Miscellaneous archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:27 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.