Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2004
    Location
    Baton Rouge, LA
    Posts
    26

    Unanswered: Nested arguments in IF statement

    I'm trying to add nested arguments to an IF statement.

    What I am trying to accomplish is to only run the code following the code if:
    1) a session hasn't been started...
    2) the first three octets of the IP address don't match the octets from my home network or from the W3C (I have a link to the validator on my footer)

    Currently, the opening of the IF looks like this...
    Code:
    if(!isset($_SESSION['USERID']) && ($firstthreeip != '192.168.1' || $firstthreeip != '128.30.52'))
    When my code only checked for no session and an IP that didn't match my network, it worked...
    Code:
    if(!isset($_SESSION['USERID']) && $firstthreeip != '192.168.1')
    Somehow I need to do the "my network or the W3 network".

    Any thoughts?
    Beau B. "desigBEAU"

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    mebbe Im missing a trick here but can't you 'just' simplify the IF
    Code:
    if (!isset($_SESSION['USERID']) AND
     ($firstthreeip != '192.168.1' OR $firstthreeip != '128.30.52'))

  3. #3
    Join Date
    Jan 2004
    Location
    Baton Rouge, LA
    Posts
    26
    According to my lovely PHP reference book, && = AND and || = OR, so unless I'm not seeing something, those to statements are the same?
    Beau B. "desigBEAU"

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    they may well be the same according to the manual but y'never know
    Id probably go one stage further..
    Code:
    if (isset($_SESSION['USERID'])==FALSE AND NOT
     ($firstthreeip == '192.168.1' OR $firstthreeip == '128.30.52'))
    I did think that the && and || operators were explicitly for byte operations

    I think you are saying you want to process this block
    if the session Id isn't set AND the networkID is neither 192.168.1 OR 128.30.52

    I take it you are checking to see what the value of $firstthreeip is what you are expecting and not something like "192.168.1."

    personally I don't like seeign operators that are !=. but thats just one of my (many) bugbears

  5. #5
    Join Date
    Jan 2004
    Location
    Baton Rouge, LA
    Posts
    26
    I used your code, and it returned a 500 Server Error. I changed the NOT to a ! and the error went away, and I'm getting the results I want.

    I take it you are checking to see what the value of $firstthreeip is what you are expecting and not something like "192.168.1."
    What I'm doing is increasing a counter number by 1 if 1)a session doesn't exist and 2)the IP address is from something other than my internal network or the W3C (because I'm constantly validating my code everytime I make an HTML change).

    If those two conditions don't exist, then the visitor "must" be new (at least since the last time they opened their browser).
    Beau B. "desigBEAU"

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by desigBEAU
    I used your code, and it returned a 500 Server Error. I changed the NOT to a ! and the error went away, and I'm getting the results I want.
    glad you foudn a solution

    one of the problems I find is trhat with so many db's out there, and not using each and evryone daly/frequently its easy to forget the precise syntax for each SQL engine

  7. #7
    Join Date
    Jan 2004
    Location
    Baton Rouge, LA
    Posts
    26
    AH! Maybe that was our confusion. This is PHP, not the SQL in the PHP. But yes, the syntax is always different from place to place.

    Regardless, I thank you for your help!
    Beau B. "desigBEAU"

Posting Permissions

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