首页 > 编程知识 正文

php如何获取客户端的IP地址,php获取客户端连接时间

时间:2023-05-03 08:50:38 阅读:15788 作者:2144

代码简洁,功能实用,这里不说多余的话。 直接给您:

//*

*获取客户端IP

* @param integer $type返回类型0:string、1:long

* @ return string >

*/

functiongetclientip($type=0) {

$ IP=空;

if (isset ($ _ server (‘http _ x _ forwarded _ for‘)’) ) )

$arr=explode(‘(、)、(、$_server )、(http_x_forwarded_for ) );

$ pos=array _ search (‘unknown’,$arr );

if (假!====$pos(unset ) $arr ) $pos );

$IP=Trim($arr[0];

} else if (isset ($ _ server (‘http _ client _ IP‘)’) ) )

$ip=$_SERVER[‘HTTP_CLIENT_IP‘];

} else if (isset ($ _ server [‘remote _ addr‘] ) ) )

$ip=$_SERVER[‘REMOTE_ADDR‘];

}

$long=sprintf('%u ',IP2long ) $IP );

$ip=$long? array($IP、$long ) :array ).0.0 )、0 );

返回$ IP [ $ type ];

}

//*

*获取IP信息

* @param string|long $ip IP地址

* @return array

*/

函数getipinfo ($ IP ) )。

{

if(is_long($IP ) ) {

$IP=long2IP($IP;

}

$ API=‘http://IP.Tao Bao.com/service/getip info.PHP‘;

$ret=file_get_contents($API.‘? ip=‘ . $ip;

$ret=JSON_decode($ret,true );

if$ret[‘code‘]==0]{

return $ret[‘data‘];

}

返回阵列(;

}

以上就是正文的全部。 我希望大家喜欢。

译文: 3358 www.jb51.net/article/62362.htm

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。