3

当网站使用CDN后获取客户端真实IP的方法

 2 years ago
source link: https://blogread.cn/it/article/1870?f=hot1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
您现在的位置首页 --> PHP --> 当网站使用CDN后获取客户端真实IP的方法

当网站使用CDN后获取客户端真实IP的方法

浏览:4134次  出处信息
  1. function get_client_ip()
  2.     $ip=false;
  3.     if(!empty($_SERVER["HTTP_CLIENT_IP"]))
  4.         $ip = $_SERVER["HTTP_CLIENT_IP"];
  5.     if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
  6.         $ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
  7.         if ($ip)
  8.             array_unshift($ips, $ip); $ip = FALSE;
  9.         for ($i = 0; $i < count($ips); $i++)
  10.             if (!eregi ("^(10|172\.16|192\.168)\.", $ips[$i]))
  11.                 $ip = $ips[$i];
  12.                 break;
  13.     return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);

建议继续学习:

QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK