PHP程序员站--PHP编程开发平台
 当前位置:主页 >> PHP基础 >> 基础文章 >> 

PHP获取仿客IP地址的函数

PHP获取仿客IP地址的函数

来源:互联网  作者:未知  发布时间:2007-12-17
function getIP (){ if( getenv ( 'HTTP_CLIENT_IP' )){ $ip = getenv ( 'HTTP_CLIENT_IP' ); } elseif( getenv ( 'HTTP_X_FORWARDED_FOR' )){ $ip = getenv ( 'HTTP_X_FORWARDED_FOR' ); } elseif( getenv ( 'HTTP_X_FORWARDED' )){ $ip = getenv ( 'HTTP_X
记录访客ip地址,可以查看访客的来源地址.对网站的优化及为重要.以下为获取ip的万能函数.

以下为引用的内容:
function getIP() {
        if (
getenv('HTTP_CLIENT_IP'
)) {
                        
$ip getenv('HTTP_CLIENT_IP'
);


                }
                elseif (
getenv('HTTP_X_FORWARDED_FOR'
)) {
                        
$ip getenv('HTTP_X_FORWARDED_FOR'
);
                }
                elseif (
getenv('HTTP_X_FORWARDED'
)) {

                        
$ip getenv('HTTP_X_FORWARDED'
);
                }
                elseif (
getenv('HTTP_FORWARDED_FOR'
)) {
                        
$ip getenv('HTTP_FORWARDED_FOR'
);


                }
                elseif (
getenv('HTTP_FORWARDED'
)) {
                        
$ip getenv('HTTP_FORWARDED'
);
                }
                else {
                        
$ip $_SERVER['REMOTE_ADDR'
];
                }
                return 
$ip
;
}
Tags: 函数   地址   ip   php  
最新文章
推荐阅读
月点击排行榜
PHP程序员站 Copyright © 2007-2010,PHPERZ.COM All Rights Reserved 粤ICP备07503606号