/    Sign up×
Community /Pin to ProfileBookmark

Whats the difference

[code=php]if ($username == $susername and $password == $spassword)[/code]

and

[code=php]if ($username == $susername & $password == $spassword)[/code]

Is there a better method

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@PineSolPirateMay 31.2007 — http://www.php.net/manual/en/language.operators.logical.php

No real difference.

No alternative I know of.

I use two &'s, but one works too.

[B]Correction[/B] The '&&' operator has higher precedence than the 'and' operator.
Copy linkTweet thisAlerts:
@redhatlookMay 31.2007 — this code is wrong
if ($username == $susername & $password == $spassword) [/QUOTE]

& is a bitwise operator

&& is a logical operator
Copy linkTweet thisAlerts:
@MrCoderMay 31.2007 — Make sure all the values are typecasted as strings.

If the client passed the username of "0" and the password of "0" this could match since strings when compared with == will concate to the numeric value of 0.

This is quite advanced but it is something to look out for, always compare with === insted of == if you know what type of value you are comparing.
×

Success!

Help @oo7ml spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...