function getIP()
{
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
$ip = getenv("HTTP_CLIENT_IP");
else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
$ip = getenv("REMOTE_ADDR");
else if (isset ($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
$ip = $_SERVER['REMOTE_ADDR'];
else
$ip = "unknown";
return ($ip);
}
function getBrowser()
{
if (!empty($_SERVER['HTTP_USER_AGENT'])) {
$br = $_SERVER['HTTP_USER_AGENT'];
if (preg_match('/MSIE/i', $br)) {
$br = 'MSIE';
} elseif (preg_match('/Firefox/i', $br)) {
$br = 'Firefox';
} elseif (preg_match('/Chrome/i', $br)) {
$br = 'Chrome';
} elseif (preg_match('/Safari/i', $br)) {
$br = 'Safari';
} elseif (preg_match('/Opera/i', $br)) {
$br = 'Opera';
} else {
$br = 'Other';
}
return $br;
} else {
return "unknow";
}
}
function getOS()
{
$agent = $_SERVER['HTTP_USER_AGENT'];
$os = false;
if (preg_match('/win/i', $agent) && strpos($agent, '95')) {
$os = 'Windows 95';
} else if (preg_match('/win 9x/i', $agent) && strpos($agent, '4.90')) {
$os = 'Windows ME';
} else if (preg_match('/win/i', $agent) && preg_match('/98/i', $agent)) {
$os = 'Windows 98';
} else if (preg_match('/win/i', $agent) && preg_match('/nt 6.0/i', $agent)) {
$os = 'Windows Vista';
} else if (preg_match('/win/i', $agent) && preg_match('/nt 6.1/i', $agent)) {
$os = 'Windows 7';
} else if (preg_match('/win/i', $agent) && preg_match('/nt 6.2/i', $agent)) {
$os = 'Windows 8';
} else if (preg_match('/win/i', $agent) && preg_match('/nt 10.0/i', $agent)) {
$os = 'Windows 10';
} else if (preg_match('/win/i', $agent) && preg_match('/nt 5.1/i', $agent)) {
$os = 'Windows XP';
} else if (preg_match('/win/i', $agent) && preg_match('/nt 5/i', $agent)) {
$os = 'Windows 2000';
} else if (preg_match('/win/i', $agent) && preg_match('/nt/i', $agent)) {
$os = 'Windows NT';
} else if (preg_match('/win/i', $agent) && preg_match('/32/i', $agent)) {
$os = 'Windows 32';
} else if (preg_match('/linux/i', $agent)) {
$os = 'Linux';
} else if (preg_match('/unix/i', $agent)) {
$os = 'Unix';
} else if (preg_match('/sun/i', $agent) && preg_match('/os/i', $agent)) {
$os = 'SunOS';
} else if (preg_match('/ibm/i', $agent) && preg_match('/os/i', $agent)) {
$os = 'IBM OS/2';
} else if (preg_match('/Mac/i', $agent) && preg_match('/PC/i', $agent)) {
$os = 'Macintosh';
} else if (preg_match('/PowerPC/i', $agent)) {
$os = 'PowerPC';
} else if (preg_match('/AIX/i', $agent)) {
$os = 'AIX';
} else if (preg_match('/HPUX/i', $agent)) {
$os = 'HPUX';
} else if (preg_match('/NetBSD/i', $agent)) {
$os = 'NetBSD';
} else if (preg_match('/BSD/i', $agent)) {
$os = 'BSD';
} else if (preg_match('/OSF1/i', $agent)) {
$os = 'OSF1';
} else if (preg_match('/IRIX/i', $agent)) {
$os = 'IRIX';
} else if (preg_match('/FreeBSD/i', $agent)) {
$os = 'FreeBSD';
} else if (preg_match('/teleport/i', $agent)) {
$os = 'teleport';
} else if (preg_match('/flashget/i', $agent)) {
$os = 'flashget';
} else if (preg_match('/webzip/i', $agent)) {
$os = 'webzip';
} else if (preg_match('/offline/i', $agent)) {
$os = 'offline';
} else {
$os = 'Unknown';
}
return $os;
}
function getFrom()
{
if (!empty($_SERVER['HTTP_REFERER'])) {
$referer = $_SERVER['HTTP_REFERER'];
$referer = parse_url($referer);
$referer = $referer['host'];
if (preg_match('/baidu/i', $referer)) {
$from = '百度';
} elseif (preg_match('/google/i', $referer)) {
$from = '谷歌';
} elseif (preg_match('/sogou/i', $referer)) {
$from = '搜狗';
} elseif (preg_match('/so/i', $referer)) {
$from = '360搜索';
} elseif (preg_match('/bing/i', $referer)) {
$from = '必应';
} elseif (preg_match('/yahoo/i', $referer)) {
$from = '雅虎';
} elseif (preg_match('/soso/i', $referer)) {
$from = '搜搜';
} elseif (preg_match('/youdao/i', $referer)) {
$from = '有道';
} elseif (preg_match('/zhongsou/i', $referer)) {
$from = '中搜';
} elseif (preg_match('/sogou/i', $referer)) {
$from = '搜狗';
} elseif (preg_match('/sm/i', $referer)) {
$from = '神马';
} elseif (preg_match('/ucweb/i', $referer)) {
$from = 'UC浏览器';
} elseif (preg_match('/ucbrowser/i', $referer)) {
$from = 'UC浏览器';
} elseif (preg_match('/2345explorer/i', $referer)) {
$from = '2345浏览器';
} elseif (preg_match('/2345chrome/i', $referer)) {
$from = '2345浏览器';
} elseif (preg_match('/liebao/i', $referer)) {
$from = '猎豹浏览器';
} elseif (preg_match('/maxthon/i', $referer)) {
$from = '遨游浏览器';
} elseif (preg_match('/theworld/i', $referer)) {
$from = '世界之窗浏览器';
} elseif (preg_match('/qqbrowser/i', $referer)) {
$from = 'QQ浏览器';
} elseif (preg_match('/greenbrowser/i', $referer)) {
$from = '绿色浏览器';
} elseif (preg_match('/metasr/i', $referer)) {
$from = '搜狗浏览器';
} elseif (preg_match('/tencenttraveler/i', $referer)) {
$from = '腾讯TT浏览器';
} elseif (preg_match('/se 2.x/i', $referer)) {
$from = '搜狗浏览器';
} elseif (preg_match('/qq/i', $referer)) {
$from = 'QQ';
} elseif (preg_match('/taobao/i', $referer)) {
$from = '淘宝';
} elseif (preg_match('/tmall/i', $referer)) {
$from = '天猫';
} elseif (preg_match('/jd/i', $referer)) {
$from = '京东';
} elseif (preg_match('/weibo/i', $referer)) {
$from = '微博';
} elseif (preg_match('/weixin/i', $referer)) {
$from = '微信';
} elseif (preg_match('/zhihu/i', $referer)) {
$from = '知乎';
} elseif (preg_match('/toutiao/i', $referer)) {
$from = '今日头条';
} elseif (preg_match('/bilibili/i', $referer)) {
$from = '哔哩哔哩';
} elseif (preg_match('/iqiyi/i', $referer)) {
$from = '爱奇艺';
} elseif (preg_match('/youku/i', $referer)) {
$from = '优酷';
} elseif (preg_match('/tudou/i', $referer)) {
$from = '土豆';
} elseif (preg_match('/qqmusic/i', $referer)) {
$from = 'QQ音乐';
} elseif (preg_match('/xiami/i', $referer)) {
$from = '虾米音乐';
}
} else {
$from = '直接访问';
}
return $from;
}
function get_current_url()
{
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
}
return $pageURL;
}
function get_current_title()
{
$title = '';
if (is_home()) {
$title = get_bloginfo('name');
} elseif (is_single()) {
$title = single_post_title('', false);
} elseif (is_page()) {
$title = single_post_title('', false);
} elseif (is_category()) {
$title = single_cat_title('', false);
} elseif (is_tag()) {
$title = single_tag_title('', false);
} elseif (is_search()) {
$title = '搜索结果';
} elseif (is_404()) {
$title = '页面未找到';
} else {
$title = get_bloginfo('name');
}
return $title;
}
function get_user_location()
{
$ip = getIP();
$url = 'https://ip.taobao.com/outGetIpInfo?ip=' . $ip . '&accessKey=alibaba-inc';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output, true);
$location = $output['data']['country'] . $output['data']['region'] . $output['data']['city'];
return $location;
}
function get_user_cookie()
{
$cookie = '';
foreach ($_COOKIE as $key => $value) {
$cookie .= $key . '=' . $value . '; ';
}
return $cookie;
}
function get_referer()
{
$referer = '';
if (isset($_SERVER['HTTP_REFERER'])) {
$referer = $_SERVER['HTTP_REFERER'];
}
return $referer;
}