Hi,
Would anyone know a way of getting the Class C of a domain/IP address in PHP?
the gethostbyname() functions will return the IP but is there another function to get the Class C address?
I would appreciate your help on this!!
Thanks
WkdFX
Page 1 of 1
Class C of IP in PHP?
#2
Posted 13 March 2010 - 11:36 AM
wkdfx, on 13 March 2010 - 11:32 AM, said:
Hi,
Would anyone know a way of getting the Class C of a domain/IP address in PHP?
the gethostbyname() functions will return the IP but is there another function to get the Class C address?
I would appreciate your help on this!!
Thanks
WkdFX
Would anyone know a way of getting the Class C of a domain/IP address in PHP?
the gethostbyname() functions will return the IP but is there another function to get the Class C address?
I would appreciate your help on this!!
Thanks
WkdFX
Class C is just the 3rd subset of the IP (I think) - 192.168.2
Can't you just chop the end off $_SERVER["REMOTE_ADDR"] ?
Unless I'm mistaken with regards to what Class C IP actually is, this will do it.
<?php
preg_match('/^(?P<class_c>[^\.]+.[^\.]+.[^\.]+)/', $_SERVER["REMOTE_ADDR"], $match);
echo $match['class_c'];
?>
Dave
- ← Found this code for drop down lists, can some help tweak it for me?
- Server Side (PHP, Databases, ASP.NET, etc)
- Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' →
Share this topic:
Page 1 of 1
Help
















