简体   繁体   English

我如何获取局域网中使用php从本地服务器访问网页的系统的IP地址

[英]How can i get IP address of systems in a local network which accessing the webpage from local server using php

I have a local network which connected to internet through a proxy server, The proxy server IP address is 192.168.0.1 . 我有一个通过代理服务器连接到Internet的局域网,代理服务器IP地址为192.168.0.1 All systems in the network assigned IP address manually like 192.168.0-6.1-255 ,Subnet mask 255.255.248.0, Default gateway 192.168.0.1 网络中的所有系统都手动分配了IP地址,例如192.168.0-6.1-255,子网掩码255.255.248.0, Default gateway 192.168.0.1

and i created another server in local network for accessing my website locally and its IP address is 192.168.0.25 , Subnet Mask 255.255.255.0, Default gateway 192.168.0.25 我在本地网络中创建了另一台服务器以供本地访问我的网站,其IP地址为192.168.0.25 ,子网掩码255.255.255.0,默认网关192.168.0.25

All the systems in the local network can now access the website using the address 现在,本地网络中的所有系统都可以使用该地址访问该网站

http://192.168.0.25/

I have to track all the systems accessing my website so i used the function $_SERVER['REMOTE_ADDR'] in php. 我必须跟踪访问我网站的所有系统,因此我在php中使用了功能$_SERVER['REMOTE_ADDR'] But i getting the IP address of all system which accessing my website is as same as the proxy server IP address( 192.168.0.1 ). 但是我得到访问我的网站的所有系统的IP地址与代理服务器的IP地址( 192.168.0.1 )相同。

Please help me to get the correct IP address of each system. 请帮助我获取每个系统的正确IP地址。

try this 尝试这个

if (!empty($_SERVER['HTTP_CLIENT_IP'])) {   //check ip from share internet
        $ip = $_SERVER['HTTP_CLIENT_IP'];
    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {   //to check ip is pass from proxy
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }
function getRealIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))  
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) 
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

echo $userIP = getRealIpAddr();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM