File "function.php"
Full Path: /www/wwwroot/shphe-en.com/wp-content/plugins/easyiit_stats/function/function.php
File size: 16.74 KB
MIME-type: --
Charset: utf-8
<?
function getip_tiny($ip, $ipdatafile) {
static $fp = NULL, $offset = array(), $index = NULL;
$ipdot = explode('.', $ip);
$ip = pack('N', ip2long($ip));
$ipdot[0] = (int)$ipdot[0];
$ipdot[1] = (int)$ipdot[1];
if ($fp === NULL && $fp = @fopen($ipdatafile, 'rb')) {
$offset = @unpack('Nlen', @fread($fp, 4));
$index = @fread($fp, $offset['len'] - 4);
} elseif ($fp == FALSE) {
return '- Invalid IP data file';
}
$length = $offset['len'] - 1028;
$start = @unpack('Vlen', $index[$ipdot[0] * 4] . $index[$ipdot[0] * 4 + 1] . $index[$ipdot[0] * 4 + 2] . $index[$ipdot[0] * 4 + 3]);
for ($start = $start['len'] * 8 + 1024;$start < $length;$start+= 8) {
if ($index{$start} . $index{$start + 1} . $index{$start + 2} . $index{$start + 3} >= $ip) {
$index_offset = @unpack('Vlen', $index{$start + 4} . $index{$start + 5} . $index{$start + 6} . "\x0");
$index_length = @unpack('Clen', $index{$start + 7});
break;
}
}
@fseek($fp, $offset['len'] + $index_offset['len'] - 1024);
if ($index_length['len']) {
return '- ' . @fread($fp, $index_length['len']);
} else {
return '- Unknown';
}
}
function getip_full($ip, $ipdatafile) {
if (!$fd = @fopen($ipdatafile, 'rb')) {
return '- Invalid IP data file';
}
$ip = explode('.', $ip);
$ipNum = $ip[0] * 16777216 + $ip[1] * 65536 + $ip[2] * 256 + $ip[3];
if (!($DataBegin = fread($fd, 4)) || !($DataEnd = fread($fd, 4))) return;
@$ipbegin = implode('', unpack('L', $DataBegin));
if ($ipbegin < 0) $ipbegin+= pow(2, 32);
@$ipend = implode('', unpack('L', $DataEnd));
if ($ipend < 0) $ipend+= pow(2, 32);
$ipAllNum = ($ipend - $ipbegin) / 7 + 1;
$BeginNum = $ip2num = $ip1num = 0;
$ipAddr1 = $ipAddr2 = '';
$EndNum = $ipAllNum;
while ($ip1num > $ipNum || $ip2num < $ipNum) {
$Middle = intval(($EndNum + $BeginNum) / 2);
fseek($fd, $ipbegin + 7 * $Middle);
$ipData1 = fread($fd, 4);
if (strlen($ipData1) < 4) {
fclose($fd);
return '- System Error';
}
$ip1num = implode('', unpack('L', $ipData1));
if ($ip1num < 0) $ip1num+= pow(2, 32);
if ($ip1num > $ipNum) {
$EndNum = $Middle;
continue;
}
$DataSeek = fread($fd, 3);
if (strlen($DataSeek) < 3) {
fclose($fd);
return '- System Error';
}
$DataSeek = implode('', unpack('L', $DataSeek . chr(0)));
fseek($fd, $DataSeek);
$ipData2 = fread($fd, 4);
if (strlen($ipData2) < 4) {
fclose($fd);
return '- System Error';
}
$ip2num = implode('', unpack('L', $ipData2));
if ($ip2num < 0) $ip2num+= pow(2, 32);
if ($ip2num < $ipNum) {
if ($Middle == $BeginNum) {
fclose($fd);
return '- Unknown';
}
$BeginNum = $Middle;
}
}
$ipFlag = fread($fd, 1);
if ($ipFlag == chr(1)) {
$ipSeek = fread($fd, 3);
if (strlen($ipSeek) < 3) {
fclose($fd);
return '- System Error';
}
$ipSeek = implode('', unpack('L', $ipSeek . chr(0)));
fseek($fd, $ipSeek);
$ipFlag = fread($fd, 1);
}
if ($ipFlag == chr(2)) {
$AddrSeek = fread($fd, 3);
if (strlen($AddrSeek) < 3) {
fclose($fd);
return '- System Error';
}
$ipFlag = fread($fd, 1);
if ($ipFlag == chr(2)) {
$AddrSeek2 = fread($fd, 3);
if (strlen($AddrSeek2) < 3) {
fclose($fd);
return '- System Error';
}
$AddrSeek2 = implode('', unpack('L', $AddrSeek2 . chr(0)));
fseek($fd, $AddrSeek2);
} else {
fseek($fd, -1, SEEK_CUR);
}
while (($char = fread($fd, 1)) != chr(0)) $ipAddr2.= $char;
$AddrSeek = implode('', unpack('L', $AddrSeek . chr(0)));
fseek($fd, $AddrSeek);
while (($char = fread($fd, 1)) != chr(0)) $ipAddr1.= $char;
} else {
fseek($fd, -1, SEEK_CUR);
while (($char = fread($fd, 1)) != chr(0)) $ipAddr1.= $char;
$ipFlag = fread($fd, 1);
if ($ipFlag == chr(2)) {
$AddrSeek2 = fread($fd, 3);
if (strlen($AddrSeek2) < 3) {
fclose($fd);
return '- System Error';
}
$AddrSeek2 = implode('', unpack('L', $AddrSeek2 . chr(0)));
fseek($fd, $AddrSeek2);
} else {
fseek($fd, -1, SEEK_CUR);
}
while (($char = fread($fd, 1)) != chr(0)) $ipAddr2.= $char;
}
fclose($fd);
if (preg_match('/http/i', $ipAddr2)) {
$ipAddr2 = '';
}
$ipaddr = "$ipAddr1 $ipAddr2";
$ipaddr = preg_replace('/CZ88\.NET/is', '', $ipaddr);
$ipaddr = preg_replace('/^\s*/is', '', $ipaddr);
$ipaddr = preg_replace('/\s*$/is', '', $ipaddr);
if (preg_match('/http/i', $ipaddr) || $ipaddr == '') {
$ipaddr = '- Unknown';
}
return '- ' . $ipaddr;
}
function GetWebContent($url, $data) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($data)));
$curl_response = curl_exec($curl);
if ($curl_response === false) {
$info = curl_getinfo($curl);
curl_close($curl);
}
curl_close($curl);
return $curl_response;
}
function goback($str, $alertstr) //为空时后退
{
if ($str == "") {
echo "<script>";
echo "alert('" . $alertstr . "');";
echo "history.go(-1)";
echo "</script>";
exit;
} else {
return $str;
}
}
function alertback($alertstr, $backnum) {
echo "<script>";
echo "alert('" . $alertstr . "');";
echo "history.go(-" . $backnum . ")";
echo "</script>";
exit;
}
function alerturl($alertstr, $url) {
echo "<script>";
echo "alert('" . $alertstr . "');";
echo "location.href='" . $url . "';";
echo "</script>";
exit;
}
function alertclose($alertstr) {
echo "<script>";
echo "alert('" . $alertstr . "');";
echo "window.close();";
echo "</script>";
exit;
}
function gotourl($url) {
echo "<script>";
echo "location.href='" . $url . "';";
echo "</script>";
exit;
}
function chkstr($paravalue, $paratype) //过滤非法字符
{
if ($paratype == 1) {
$filterstr = "(and|or)\\b.+?(>|<|=|in|like)|\\/\\*.+?\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\\s+(TABLE|DATABASE)";
if (preg_match("/" . $filterstr . "/is", $paravalue) == 1) {
echo "传递的参数类型有错误!";
exit;
}
$inputstr = str_replace("'", "''", $paravalue);
} elseif ($paratype == 2) {
if ($paravalue != "" && is_numeric($paravalue) == false) {
echo "传递的参数类型有错误!";
exit;
} else {
$inputstr = $paravalue;
}
} elseif ($paratype == 3) {
if ($paravalue != "" && (strtotime($paravalue) == false || strtotime($paravalue) == - 1)) {
echo ("传递的参数类型有错误!");
exit;
} else {
$inputstr = $paravalue;
}
}
return $inputstr;
}
function httppath($assort) {
$ser = $_SERVER['HTTP_HOST'];
$scr = $_SERVER['SCRIPT_NAME'];
$scr_2 = substr($scr, 0, strrpos($scr, "/") + 1);
if ($assort == 1) {
$httppath = $ser;
} elseif ($assort == 2) {
$httppath = "http://" . $ser . $scr_2;
} elseif ($assort == 3) {
$httppath = "http://" . $ser . $scr;
}
return $httppath;
}
function breakurl($url) {
if ($url <> "") {
$urlarrary = explode("/", $url);
$breakurl = $urlarrary[2];
} else {
$breakurl = $url;
}
return $breakurl;
}
function pxfilter($px, $pxok) {
$px = strtolower($px);
$pxok = strtolower($pxok);
$myarray = explode(",", $pxok);
for ($i = 0;$i <= count($myarray) - 1;$i++) {
if ($myarray[$i] == $px) {
$j = 1;
}
}
if ($j <> 1) alertback("禁止此类排序", 1);
}
function getsearchkeyword($url, $keywordflag) {
if (strpos($url, "?" . $keywordflag . "=") !== false) {
$keywordflag = "?" . $keywordflag . "=";
}
if (strpos($url, "&" . $keywordflag . "=") !== false) {
$keywordflag = "&" . $keywordflag . "=";
}
$urlarrary = explode($keywordflag, $url);
$urltail = $urlarrary[1];
if (strpos($urltail, "&") == false) {
$searchkeyword = substr($urltail, 0, 1000);
} else {
$searchkeyword = substr($urltail, 0, strpos($urltail, "&"));
}
return $searchkeyword;
}
function getiparea($ip) {
$array = explode('.', $ip);
$ipint = ($array[0] * 256 * 256 * 256) + ($array[1] * 256 * 256) + ($array[2] * 256) + $array[3];
$sql = "select * from wp_stats_ipaddress where $ipint>=ip_1 and $ipint<=ip_2";
$result = mysql_query($sql);
$rs = mysql_fetch_assoc($result);
if ($rs) {
$iparea = $rs["area"] . "-" . $rs["area_2"] . "-" . $rs["area_3"];
} else {
$iparea = "<a href='http://www.qqcf.com' target=_blank>IP数据库无数据-下载</a>";
}
return $iparea;
}
function getskincolor($skincolor, $assort) {
$myarray = explode("|", $skincolor);
if ($assort <= count($myarray)) {
return $myarray[$assort];
}
}
function watermark($infilename, $string, $fontfilename, $fontsize, $distancefromborder, $fontcolorarray, $shadecolorarray, $stringbottom) {
$imagefile = fopen($infilename, "r");
$imagestring = fread($imagefile, filesize($infilename));
fclose($imagefile);
$image = ImageCreateFromString($imagestring);
$imagewidth = ImageSX($image);
$imageheight = ImageSY($image);
$stringbox = ImageTTFBBox($fontsize, 0, $fontfilename, $string);
$stringwidth = $stringbox[2] - $stringbox[0];
$stringheight = $stringbox[1] - $stringbox[7];
$stringright = $imagewidth - $distancefromborder;
$stringleft = 10;
//$stringbottom=20;
$stringtop = 0;
$fontcolor = ImageColorAllocateAlpha($image, $fontcolorarray[0], $fontcolorarray[1], $fontcolorarray[2], $fontcolorarray[3]);
$shadecolor = ImageColorAllocateAlpha($image, $shadecolorarray[0], $shadecolorarray[1], $shadecolorarray[2], $shadecolorarray[3]);
ImageTTFText($image, $fontsize, 0, $stringleft, $stringbottom - 1, $shadecolor, $fontfilename, $string);
ImageTTFText($image, $fontsize, 0, $stringleft + 1, $stringbottom, $shadecolor, $fontfilename, $string);
ImageTTFText($image, $fontsize, 0, $stringleft, $stringbottom + 1, $shadecolor, $fontfilename, $string);
ImageTTFText($image, $fontsize, 0, $stringleft - 1, $stringbottom, $shadecolor, $fontfilename, $string);
ImageTTFText($image, $fontsize, 0, $stringleft, $stringbottom, $fontcolor, $fontfilename, $string);
$outfilename = substr($infilename, 0, -4) . "_$string.png";
header("Content-type: image/png");
ImagePng($image);
ImageDestroy($image);
}
function getostype() {
$agentinfo = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strpos($agentinfo, 'micromessenger') != false) {
$ostype = "微信";
} elseif (strpos($agentinfo, 'android') != false) {
$ostype = "安卓";
} elseif (strpos($agentinfo, 'iphone') != false) {
$ostype = "iPhone";
} elseif (strpos($agentinfo, 'ipad') != false) {
$ostype = "iPad";
} elseif (strpos($agentinfo, 'nt 10') != false) {
$ostype = "Windows 10";
} elseif (strpos($agentinfo, 'nt 6.4') != false) {
$ostype = "Windows 10";
} elseif (strpos($agentinfo, 'nt 6.3') != false) {
$ostype = "Windows 8";
} elseif (strpos($agentinfo, 'nt 6.2') != false) {
$ostype = "Windows 8";
} elseif (strpos($agentinfo, 'nt 6.1') != false) {
$ostype = "Windows 7";
} elseif (strpos($agentinfo, 'nt 6.0') != false) {
$ostype = "Windows Vista";
} elseif (strpos($agentinfo, 'nt 5.2') != false) {
$ostype = "Windows 2003";
} elseif (strpos($agentinfo, 'nt 5.1') != false) {
$ostype = "Windows XP";
} elseif (strpos($agentinfo, 'nt 5') != false) {
$ostype = "Windows 2000";
} elseif (strpos($agentinfo, 'nt 4.9') != false) {
$ostype = "Windows ME";
} elseif (strpos($agentinfo, 'nt 4') != false) {
$ostype = "Windows NT4";
} elseif (strpos($agentinfo, 'nt 98') != false) {
$ostype = "Windows 98";
} elseif (strpos($agentinfo, 'nt 95') != false) {
$ostype = "Windows 95";
} elseif (strpos($agentinfo, 'nt') != false) {
$ostype = "Windows";
} elseif (strpos($agentinfo, 'mac') != false) {
$ostype = "Mac";
} elseif (strpos($agentinfo, 'unix') != false) {
$ostype = "Unix";
} elseif (strpos($agentinfo, 'linux') != false) {
$ostype = "Linux";
} elseif (strpos($agentinfo, 'sunos') != false) {
$ostype = "SunOS";
} else {
$ostype = "其他";
}
return $ostype;
}
function getbrowsertype() {
$agentinfo = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strpos($agentinfo, 'se 2.x') != false) {
$browsertype = "搜狗";
} elseif (strpos($agentinfo, 'maxthon') != false) {
$browsertype = "遨游";
} elseif (strpos($agentinfo, '360se') != false) {
$browsertype = "360";
} elseif (strpos($agentinfo, 'taobrowser') != false) {
$browsertype = "淘宝";
} elseif (strpos($agentinfo, 'lbbrowser') != false) {
$browsertype = "猎豹";
} elseif (strpos($agentinfo, 'ubrowser') != false) {
$browsertype = "UC";
} elseif (strpos($agentinfo, 'tencenttraveler') != false) {
$browsertype = "腾讯";
} elseif (strpos($agentinfo, 'firefox') != false) {
$browsertype = "火狐";
} elseif (strpos($agentinfo, '115browser') != false) {
$browsertype = "115浏览器";
} elseif (strpos($agentinfo, 'theworld') != false) {
$browsertype = "世界之窗";
} elseif (strpos($agentinfo, 'opera') != false) {
$browsertype = "Opera";
} elseif (strpos($agentinfo, 'safar') != false) {
$browsertype = "Safar";
} elseif (strpos($agentinfo, 'greenbrowser') != false) {
$browsertype = "GreenBrowser";
} elseif (strpos($agentinfo, 'chrome') != false) {
$browsertype = "Chrome";
} elseif (strpos($agentinfo, 'msie 6.0') != false) {
$browsertype = "IE 6.0";
} elseif (strpos($agentinfo, 'msie 7.0') != false) {
$browsertype = "IE 7.0";
} elseif (strpos($agentinfo, 'msie 8.0') != false) {
$browsertype = "IE 8.0";
} elseif (strpos($agentinfo, 'msie 9.0') != false) {
$browsertype = "IE 9.0";
} elseif (strpos($agentinfo, 'msie 10.0') != false) {
$browsertype = "IE 10.0";
} elseif (strpos($agentinfo, 'rv:11') != false) {
$browsertype = "IE 11.0";
} elseif (strpos($agentinfo, 'msie') != false) {
$browsertype = "IE";
} else {
$browsertype = "其他";
}
return $browsertype;
}
function getmicrotime() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
function execute_time() {
$stime = explode(' ', SYS_START_TIME);
$etime = explode(' ', microtime());
return number_format(($etime[1] + $etime[0] - $stime[1] - $stime[0]), 6);
}
function stats_show_message($info) {
$html = '<div id="setting-error-settings_updated" class="updated settings-error"><p><strong>'.$info.'</strong></p></div>';
$html .= '
<script language="javascript">
function hide_msg(){
$("#setting-error-settings_updated").hide();
}
setTimeout(\'hide_msg()\',3000);
</script>';
return $html;
}