当前位置:Gxlcms > PHP教程 > php获取在线访客Ip地址信息的方法

php获取在线访客Ip地址信息的方法

时间:2021-07-01 10:21:17 帮助过:4人阅读

  1. if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {

  2. $onlineip = getenv('HTTP_CLIENT_IP');
  3. } elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
  4. $onlineip = getenv('HTTP_X_FORWARDED_FOR');
  5. } elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
  6. $onlineip = getenv('REMOTE_ADDR');
  7. } elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
  8. $onlineip = $_SERVER['REMOTE_ADDR'];
  9. }

  10. preg_match("/[\d\.]{7,15}/", $onlineip, $onlineipmatches);

  11. $onlineip = $onlineipmatches[0] ? $onlineipmatches[0] : 'unknown';
  12. unset($onlineipmatches);
  13. ?>

人气教程排行