欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php获取本机ip或远道地址

程序员文章站 2024-01-26 18:37:34
...
php获取本机ip或远程地址
// 111111111111echo $_SERVER['REMOTE_ADDR'];// 2222222222222function get_local_ip() {    $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/";//获取操作系统为win2000/xp、win7的本机IP真实地址    exec("ipconfig", $out, $stats);    if (!empty($out)) {        foreach ($out AS $row) {            if (strstr($row, "IP") && strstr($row, ":") && !strstr($row, "IPv6")) {                $tmpIp = explode(":", $row);                if (preg_match($preg, trim($tmpIp[1]))) {                    return trim($tmpIp[1]);                }            }        }    }//获取操作系统为linux类型的本机IP真实地址    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';}

?

php获取本机ip或远道地址

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频


网友评论

文明上网理性发言,请遵守 新闻评论服务协议

我要评论
  • php获取本机ip或远道地址
  • 专题推荐