网站首页 > 代码片段 > Php > 正文

php 判断访问IP

2017-08-26 22:29:52 来源: 点击:站内收藏
 
<?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; 
} 

?>

相关热词搜索:ip
评论正在载入