php判断访问IP的方法_PHP教程

WBOY
Release: 2016-07-13 09:49:56
Original
1069 people have browsed it

php判断访问IP的方法

 这篇文章主要介绍了php判断访问IP的方法,涉及php针对服务器端预定义变量$_SERVER的相关判断与使用技巧,需要的朋友可以参考下

 
 

本文实例讲述了php判断访问IP的方法。分享给大家供大家参考。具体如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
function getIP() { 
  if (! empty ( $_SERVER ["HTTP_CLIENT_IP"] )) { 
    $cip = $_SERVER ["HTTP_CLIENT_IP"]; 
  } else if (! empty ( $_SERVER ["HTTP_X_FORWARDED_FOR"] )) { 
    $cip = $_SERVER ["HTTP_X_FORWARDED_FOR"]; 
  } else if (! empty ( $_SERVER ["REMOTE_ADDR"] )) { 
    $cip = $_SERVER ["REMOTE_ADDR"]; 
  } else
    $cip = ''
  
  preg_match ( "/[\d\.]{7,15}/", $cip, $cips ); 
  $cip = isset ( $cips [0] ) ? $cips [0] : 'unknown'
  unset ( $cips ); 
  return $cip
?>

希望本文所述对大家的php程序设计有所帮助。

 

        :更多精彩教程请关注帮客之家网页设计教程 栏目,

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1018922.htmlTechArticlephp判断访问IP的方法 这篇文章主要介绍了php判断访问IP的方法,涉及php针对服务器端预定义变量$_SERVER的相关判断与使用技巧,需要的朋友可以...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!