Results 1 to 5 of 5

Thread: if ip check

  1. #1
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default if ip check

    i am trying to do an if ip check so that if a certain ip (namely one ip) loads the page they see additional information.

    Heres what if quickly put together but is always showing true.

    PHP Code:
    <?php
    // Get Ipaddress
    $IP getenv("REMOTE_ADDR");

    // Show IP address for test
    echo "IP:".$IP;

    // IF statement
    if ($IP "192.168.1.4") {
       echo 
    "yes you are John Grooms";
    } else {
       echo 
    "sorry you are not John Grooms";
    }
    ?>
    The network here is on a Static Ip address so the ip does not change. Everything works up to the if statement.
    Ryan
    Sevierville, TN

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You've confused = with ==.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default

    Thanks Twey i knew it was going to be something simple as that. Thanks for the help.
    Ryan
    Sevierville, TN

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    If you find you do this a lot, try putting a constant value on the other side of the operator, for example:
    Code:
    if ("192.168.1.4" == $IP) {
    It'll make no difference with == or ===, but if you inadvertantly use = it'll throw an error instead of just carrying on and not doing what you expect it to.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default

    cool thanks for the tip
    Ryan
    Sevierville, TN

Bookmarks

Posting Permissions

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