简体   繁体   English

我为每个系统获得相同的IP - 如何通过PHP编码获取IP地址

[英]I am getting same IP for every system - How to get IP Address via PHP coding

Hello i am using this function to get IP Address of different systems..but everytime it returns the same value: 117.239.82.182 您好我正在使用此函数获取不同系统的IP地址..但每次返回相同的值:117.239.82.182

function getRealIpAddr()
{
   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'];
   }
   return $ip;
}

117.239.82.182 is an external IP address. 117.239.82.182是外部IP地址。 If all the systems that connect to the PHP server are behind the same external IP address, all of them will be notet as the same IP address. 如果连接到PHP服务器的所有系统都位于相同的外部IP地址后面,则所有这些系统都将作为相同的IP地址进行通知。

Your script doesn't take the local IP. 您的脚本不使用本地IP。 Don't think it's even possible. 不要以为它甚至可能。 The IP you are seeing, is the IP of the firewall of your company. 您看到的IP是您公司防火墙的IP。

EDIT: (The answer changed radically after some clarifications in the comments) 编辑:(在评论中作出一些澄清后,答案发生了根本改变)

You could edit the User-Agent setting of the user's browsers. 您可以编辑用户浏览器的User-Agent设置。 To see how to change the setting in various browsers follow this link . 要查看如何在各种浏览器中更改设置,请点击此链接 Then you should modify your PHP script to read User-Agent of the browser. 然后,您应该修改PHP脚本以读取浏览器的User-Agent。 In PHP, $_SERVER['HTTP_USER_AGENT'] returns the browser's User-Agent setting. 在PHP中, $_SERVER['HTTP_USER_AGENT']返回浏览器的User-Agent设置。 Eg. 例如。 you can define as User-Agent something like Company/System/1.02 Bla bla bla . 你可以定义像User / System / 1.02 Bla bla bla这样的User-Agent Then when you receive that same string you can assume it is coming from a known host. 然后,当您收到相同的字符串时,您可以假设它来自已知主机。

Attention that the User-Agent can be easily spoofed. 注意用户代理很容易被欺骗。 So this method is not secure. 所以这种方法并不安全。 The secure solution would be to implement a VPN solution. 安全的解决方案是实施VPN解决方案。

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

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