1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > PHP获取浏览器信息类和客户端地理位置的2个方法【PHP】

PHP获取浏览器信息类和客户端地理位置的2个方法【PHP】

时间:2021-09-19 23:36:09

相关推荐

PHP获取浏览器信息类和客户端地理位置的2个方法【PHP】

后端开发|php教程

PHP,获取客户端信息

后端开发-php教程

A、获取浏览器信息,获取访客操作系统:windows、mac、linux、unix、bsd、other,以及访客ip地址等信息的PHP类

webapi成功的案例源码,装完Ubuntu做什么,如何局域网tomcat,爬虫软件王子,php版本下载安装,seo高效lzw

<?php

/**

* 获取访客信息的类:语言、浏览器、操作系统、ip、地理位置、isp。

* 使用:

* $obj = new guest_info;

* $obj->getlang();//获取访客语言:简体中文、繁體中文、english。

* $obj->getbrowser(); //获取访客浏览器:msie、firefox、chrome、safari、opera、other。

* $obj->getos(); //获取访客操作系统:windows、mac、linux、unix、bsd、other。

* $obj->getip(); //获取访客ip地址。

* $obj->getadd();//获取访客地理位置,使用 baidu 隐藏接口。

* $obj->getisp();//获取访客isp,使用 baidu 隐藏接口。

*/

class guest_info{

function getlang() {

$lang = substr($_server[http_accept_language], 0, 4);

//使用substr()截取字符串,从 0 位开始,截取4个字符

if (preg_match(/zh-c/i,$lang)) {

//preg_match()正则表达式匹配函数

$lang = 简体中文;

}

elseif (preg_match(/zh/i,$lang)) {

$lang = 繁體中文;

}

else {

$lang = english;

}

return $lang;

}

function getbrowser() {

$browser = $_server[http_user_agent];

if (preg_match(/msie/i,$browser)) {

$browser = msie;

}

elseif (preg_match(/firefox/i,$browser)) {

$browser = firefox;

}

elseif (preg_match(/chrome/i,$browser)) {

$browser = chrome;

}

elseif (preg_match(/safari/i,$browser)) {

$browser = safari;

}

elseif (preg_match(/opera/i,$browser)) {

$browser = opera;

}

else {

$browser = other;

}

return $browser;

}

function getos() {

$os = $_server[http_user_agent];

if (preg_match(/win/i,$os)) {

$os = windows;

}

elseif (preg_match(/mac/i,$os)) {

$os = mac;

}

elseif (preg_match(/linux/i,$os)) {

$os = linux;

}

elseif (preg_match(/unix/i,$os)) {

$os = unix;

}

elseif (preg_match(/bsd/i,$os)) {

$os = sd;

}

else {

$os = other;

}

return $os;

}

function getip() {

if (!empty($_server[http_client_ip])) {

//如果变量是非空或非零的值,则 empty()返回 false。

$ip = explode(,,$_server[http_client_ip]);

}

elseif (!empty($_server[http_x_forwarded_for])) {

$ip = explode(,,$_server[http_x_forwarded_for]);

}

elseif (!empty($_server[ emote_addr])) {

$ip = explode(,,$_server[ emote_addr]);

}

else {

$ip[0] = one;

}

return $ip[0];

}

}

$obj = new guest_info;

echo $obj->getlang(); //获取访客语言:简体中文、繁體中文、english。

echo $obj->getbrowser(); //获取访客浏览器:msie、firefox、chrome、safari、opera、other。

echo $obj->getos(); //获取访客操作系统:windows、mac、linux、unix、bsd、other。

echo $obj->getip(); //获取访客ip地址。

?>

B、php利用腾讯ip分享计划获取ip地理位置

android 安装 机器源码,vscode中怎么打出下划线,ubuntu写入镜像,tomcat访问外网走代理,nodejs接口爬虫,php类库是什么,仓山区百度推广seolzw

<?php

function getiploc_qq($queryip){

$url = /cgi-bin/searchip?searchip1=.$queryip;

$ch = curl_init($url);

curl_setopt($ch,curlopt_encoding ,gb2312);

curl_setopt($ch, curlopt_timeout, 10);

curl_setopt($ch, curlopt_returntransfer, true) ; // 获取数据返回

$result = curl_exec($ch);

$result = mb_convert_encoding($result, "utf-8", "gb2312"); // 编码转换,否则乱码

curl_close($ch);

preg_match("@(.*)

o2o营销系统源码,安装ubuntu卡在黑屏,tomcat和猫乐适,白色虫子爬虫,php检查是不是数组,seo技术我选乐云seolzw

@iu",$result,$iparray);

$loc = $iparray[1];

return $loc;

}

//使用

echo getiploc_qq("183.37.209.57"); //即可得到ip地址所在的地址位置。

?>

C、php利用新浪ip查询接口获取ip地理位置

<?php

function getiploc_sina($queryip){

$url = http://int./iplookup/iplookup.php?format=json&ip=.$queryip;

$ch = curl_init($url);

curl_setopt($ch,curlopt_encoding ,utf8);

curl_setopt($ch, curlopt_timeout, 5);

curl_setopt($ch, curlopt_returntransfer, true) ; // 获取数据返回

$location = curl_exec($ch);

$location = json_decode($location);

curl_close($ch);

$loc = "";

if($location===false) return "";

if (empty($location->desc)) {

$loc = $location->province.$location->city.$location->district.$location->isp;

}else{ $loc = $location->desc;

}

return $loc;

}

echo getiploc_sina("183.37.209.57");

?>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。