October 18th, 2000, 08:48 AM
-
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
October 18th, 2000, 08:55 AM
-
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
October 18th, 2000, 10:22 AM
-
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.
October 18th, 2000, 10:29 AM
-
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