function GetIP () {
$realip = ";
$unknown = ' unknown ';
if (Isset ($_server)) {
if (Isset ($_server[' http_x_forwarded_for ')) &&!empty ($_server[' http_x_forwarded_for ']) && STRCASECMP ($_server[' http_x_forwarded_for '), $unknown)) {
$arr = Explode (', ', $_server[' http_x_forwarded_for ');
foreach ($arr as $ip) {
$ip = Trim ($IP);
if ($ip! = ' Unknown ') {
$realip = $ip;
Break
}
}
}else if (isset ($_server[' http_client_ip ") &&!empty ($_server[' http_client_ip ']) && strcasecmp ($_ server[' Http_client_ip '], $unknown)) {
$realip = $_server[' http_client_ip ');
}else if (isset ($_server[' remote_addr ") &&!empty ($_server[' remote_addr ']) && strcasecmp ($_server[') Remote_addr '], $unknown)) {
$realip = $_server[' remote_addr ');
}else{
$realip = $unknown;
}
}else{
if (getenv (' http_x_forwarded_for ') && strcasecmp (getenv (' http_x_forwarded_for '), $unknown)) {
$realip = getenv ("Http_x_forwarded_for");
}else if (getenv (' http_client_ip ') && strcasecmp (getenv (' http_client_ip '), $unknown)) {
$realip = getenv ("Http_client_ip");
}else if (getenv (' remote_addr ') && strcasecmp (getenv (' remote_addr '), $unknown)) {
$realip = getenv ("REMOTE_ADDR");
}else{
$realip = $unknown;
}
}
$realip = Preg_match ("/[\d\.") {7,15}/", $realip, $matches)? $matches [0]: $unknown;
return $realip;
}
function Getiplookup ($ip = ") {
if (empty ($ip)) {
$ip = GetIP ();
}
$res = @file_get_contents (' http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip= '. $ip);
if (empty ($res)) {return false;}
$jsonMatches = Array ();
Preg_match (' #\{.+?\}# ', $res, $jsonMatches);
if (!isset ($jsonMatches [0])) {return false;}
$json = Json_decode ($jsonMatches [0], true);
if (Isset ($json [' ret ']) && $json [' ret '] = = 1) {
$json [' ip '] = $IP;
unset ($json [' ret ']);
}else{
return false;
}
return $json;
}
Determine if your phone is logged in
function Is_mobile () {
$is _mobile = false;
if (Empty ($_server[' http_user_agent ')) {
$is _mobile = false;
} elseif (Strpos ($_server[' http_user_agent '), ' Mobile ')!== false | | Strpos ($_server[' http_user_agent '], ' Android ')!== False | | Strpos ($_server[' http_user_agent '), ' silk/')!== false | | Strpos ($_server[' http_user_agent '), ' Kindle ')!== false | | Strpos ($_server[' http_user_agent '), ' BlackBerry ')!== false | | Strpos ($_server[' http_user_agent '), ' Opera Mini ')!== false | | Strpos ($_server[' http_user_agent '), ' Opera Mobi ')!== false) {
$is _mobile = true;
} else {
$is _mobile = false;
}
return $is _mobile;
}
Get User IP
$user _ip = ($_server["Http_via"])? $_server["Http_x_forwarded_for"]: $_server["REMOTE_ADDR"];
$user _ip = ($user _ip)? $user _ip: $_server["REMOTE_ADDR"];
Get City Information
$ipInfos = Getiplookup ($user _ip);
PHP gets IP based on IP to get city information to determine whether mobile phone login