#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    0
    Rep Power
    0
    Hello all,

    I've made a form, where users fill in an IP adress. I want to make sure the IP number isn't any higher then 255 of course, but how can I check for this?

    Perhaps a stupid question, but I'm quite new to PHP.



    ------------------
    ---------------------
    Hans Buis
    Framers
    http://www.framers.nl
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    0
    Rep Power
    0
    Stupid thinking of me.

    Did a simple thing like this:
    (192.168.100.100 is in my dbase: ip1,ip2,ip3,ip4 -> I can search for subnets this way).

    ----

    function checkvalid ($str) {

    // If a 1 is returned, it's valid
    // If a 0 is returned, no good

    $MAX = 256;

    if ($str < $MAX) {
    return 1;
    } else {
    return 0;
    }

    }

    ---

    And included a functions.php in my source, but perhaps it isn't the best solution?



    ------------------
    ---------------------
    Hans Buis
    Framers
    http://www.framers.nl
  4. #3
  5. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    Another way to accomplish this is at the database level. Since you are using a column for each triplet, (in MySQL) you could just use the column type TINYINT UNSIGNED, which has a maximum value of 255. (If you don't create it as UNSIGNED it will have a maximum positive value of 127 and a maximium negative value of -128)

    For other databases, I'm sure the syntax is vary similar. One advantage of this approach is that it optimizes your database a little more.
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    halifax
    Posts
    13
    Rep Power
    0
    you ccould try just checking the address before it goes into the db...
    try someting like this.....
    $strip = 192.168.0.1;
    $var = explode(".",$strip)
    for($i=0;$i=3){
    if ($var[$i] > 255){
    echo "bad ip portion.......";
    }
    }

    might werk for ya =)
    cryogen

Similar Threads

  1. regular expressions
    By tdennist in forum C Programming
    Replies: 2
    Last Post: January 18th, 2004, 06:01 AM
  2. regular expressions in Javascript
    By DazAdams in forum JavaScript Development
    Replies: 9
    Last Post: November 24th, 2003, 09:09 AM
  3. xml: How do I divide numbers in XSL expressions?
    By Wildman in forum Beginner Programming
    Replies: 2
    Last Post: June 30th, 2003, 02:28 AM
  4. Multiple IF expressions, one statement
    By basher in forum PHP Development
    Replies: 3
    Last Post: August 3rd, 2002, 01:28 PM
  5. Regular expressions tool
    By Harry in forum PHP Development
    Replies: 6
    Last Post: March 4th, 2002, 04:03 PM

IMN logo majestic logo threadwatch logo seochat tools logo