开启CDN后PHP获取用户真实IP的方法

<?php
function GetUserIP(){
    if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
        //为了兼容百度的CDN,所以转成数组
        $arr = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
        return $arr[0];
    }else{
        return $_SERVER['REMOTE_ADDR'];
    }
}
?>

 

阅读剩余
THE END