www.webdeveloper.com
Results 1 to 4 of 4

Thread: Whats the difference

  1. #1
    Join Date
    Jul 2006
    Posts
    653

    Whats the difference

    PHP Code:
    if ($username == $susername and $password == $spassword
    and

    PHP Code:
    if ($username == $susername $password == $spassword

    Is there a better method
    Last edited by oo7ml; 05-31-2007 at 01:18 PM.

  2. #2
    Join Date
    Jul 2006
    Location
    Nebraska
    Posts
    380
    http://www.php.net/manual/en/languag...rs.logical.php

    No real difference.
    No alternative I know of.

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

    Correction The '&&' operator has higher precedence than the 'and' operator.
    Last edited by PineSolPirate; 05-31-2007 at 02:05 PM.
    My Site
    Web Design On Linux: Sure It Takes Longer To Get It Right In IE, But Who Really Cares?

  3. #3
    Join Date
    May 2007
    Posts
    93
    this code is wrong
    if ($username == $susername & $password == $spassword)
    & is a bitwise operator
    && is a logical operator

  4. #4
    Join Date
    Jun 2006
    Location
    Down at the bottom of the garden
    Posts
    1,239
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles