This article mainly for you in detail the PHP to obtain the real IP address instance code, with a certain reference value, interested in small partners can refer to
The main is to obtain the operating system for WIN2000/XP, Win7 native IP real address, and obtain the operating system for the Linux type of native IP real address, specific content as follows
function Getlocalip () {$preg = "/\a (([[0-9]?[ 0-9]) | (1[0-9]{2}) | (2[0-4][0-9]) | (25[0-5])) \.) {3} ([0-9]? [0-9]) | (1[0-9]{2}) | (2[0-4][0-9]) | (25[0-5])) \z/";//Get the native IP address of the operating system WIN2000/XP, Win7 exec (" ipconfig ", $out, $stats); if (!empty ($out)) { foreach ($out as $row) { if (strstr ($row, "IP") && strstr ($row, ":") &&!strst R ($row, "IPv6")) { $tmpIp = explode (":", $row); if (Preg_match ($preg, Trim ($tmpIp [1])) { return trim ($tmpIp [1]);}}} Get the native IP real address of the Linux type for the OS exec ("Ifconfig", $out, $stats); if (!empty ($out)) { if (isset ($out [1]) && strstr ($out [1], ' addr: ')} { $tmpArray = explode (":", $out [1]); $tmpIp = Explode ("", $tmpArray [1]); if (Preg_match ($preg, Trim ($tmpIp [0])) { return trim ($tmpIp [0]),} } } return ' 127.0.0.1 ';}
Summary: The above is the entire content of this article, I hope to be able to help you learn.