One, access to browser information, access to the guest operating system: Windows, Mac, Linux, Unix, BSD, other, and guest IP address information such as the PHP class
Copy Code code as follows:
<?php
/**
* The class that gets the visitor information: language, browser, operating system, IP, geographic location, ISP.
Use
* $obj = new Guest_info;
* $obj->getlang (); Get guest language: Simplified Chinese, Chinese, English.
* $obj->getbrowser (); Get guest browsers: MSIE, Firefox, Chrome, Safari, opera, and other.
* $obj->getos (); Get guest OS: Windows, Mac, Linux, Unix, BSD, other.
* $obj->getip (); Gets the guest IP address.
* $obj->getadd (); Get the visitor's geographic location and use the Baidu to hide the interface.
* $obj->getisp (); Get the guest ISP and use Baidu to hide the interface.
*/
Class guest_info{
function Getlang () {
$lang = substr ($_server[' http_accept_language '), 0, 4);
Intercepts a string using substr (), starting at 0 bits and intercepting 4 characters
if (Preg_match ('/zh-c/i ', $lang)) {
Preg_match () Regular expression matching function
$lang = ' Simplified Chinese ';
}
ElseIf (Preg_match ('/zh/i ', $lang)) {
$lang = ' Traditional Chinese ';
}
else {
$lang = ' 中文版 ';
}
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 = ' BSD ';
}
else {
$os = ' other ';
}
return $os;
}
function GetIP () {
if (!empty ($_server[' http_client_ip ')) {
If the variable is non-null or Non-zero, empty () returns false.
$ip = Explode (', ', $_server[' http_client_ip '));
}
ElseIf (!empty ($_server[' http_x_forwarded_for ')) {
$ip = Explode (', ', $_server[' http_x_forwarded_for '));
}
ElseIf (!empty ($_server[' remote_addr ')) {
$ip = Explode (', ', $_server[' remote_addr '));
}
else {
$ip [0] = ' none ';
}
return $IP [0];
}
}
$obj = new Guest_info;
echo $obj->getlang (); Get guest language: Simplified Chinese, Chinese, English.
echo $obj->getbrowser (); Get guest browsers: MSIE, Firefox, Chrome, Safari, opera, and other.
echo $obj->getos (); Get guest OS: Windows, Mac, Linux, Unix, BSD, other.
echo $obj->getip (); Gets the guest IP address.
?>
Second, PHP use Tencent IP sharing program to obtain IP location
Copy Code code as follows:
<?php
function Getiploc_qq ($QUERYIP) {
$url = ' http://ip.qq.com/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); Get Data back
$result = curl_exec ($ch);
$result = mb_convert_encoding ($result, "Utf-8", "gb2312"); Code conversion, otherwise garbled
Curl_close ($ch);
Preg_match ("@<span> (. *) </span></p> @iu", $result, $iparray);
$loc = $iparray [1];
return $loc;
}
Use
Echo getiploc_qq ("183.37.209.57"); You can get the address location where the IP address resides.
?>
Third, php use Sina IP query interface to obtain IP location
Copy Code code as follows:
<?php
function Getiploc_sina ($QUERYIP) {
$url = ' http://int.dpool.sina.com.cn/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); Get Data back
$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");
?>