📄 func_common.php
字号:
<?php
include("function_double.php");
include("function_pass.php");
//设置临时访问文件COOKIE
$url_name1 = explode("/",$_SERVER['PHP_SELF']);
$url_name = $url_name1[count($url_name1)-1];
//echo $_SERVER['PHP_SELF']."|".$url_name[1];
if($url_name1[1]=="game" and $url_name1[2]<>"init"){
$url_query = $_SERVER['QUERY_STRING'];
if($url_query and $url_name<>"index.php" and $url_name<>"resource_auto_grow.php" and $url_name<>"infomation.php" and $url_name<>"UpdateResource.php" and $url_name<>"cityname_setting.php") $url_name .= "?".$url_query;
if($url_name<>"index.php"){
@setcookie("temp_filename",$url_name,time()+20*60,"/");
@$_COOKIE['temp_filename']=$url_name;
}
}
function nohtml($str) {
$str=str_replace('</p>','</p><br>',$str);
$str=str_replace('</P>','</P><br>',$str);
$str=strip_tags($str);
return($str);
}
function myhash($length,$t=0) {
$hash = '';
if ($t==0) $chars = '0123456789';else $chars = 'ACDEFGHKLMNPQRSTUVWXY345679';
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
for($i = 0; $i < $length; $i++) $hash .= $chars[mt_rand(0, $max)];
return $hash;
}
function echomsg($msg,$url="javascript:history.back(1)") {
echo "<SCRIPT language=JavaScript>";
if ($msg<>'') echo "alert(\" $msg \");";
echo "window.location='$url';</SCRIPT>";
exit;
}
function top_echomsg($msg,$url="javascript:history.back(1)") {
echo "<SCRIPT language=JavaScript>";
if ($msg<>'') echo "alert(\" $msg \");";
echo "top.window.location='$url';</SCRIPT>";
exit;
}
function error_document($error_type,$error_info,$back_url,$status="",$url="../../error_document.php"){
echo "<SCRIPT language=JavaScript>";
//if ($msg<>'') echo "alert(\" 信息:$msg \");";
echo "top.window.location='$url?back_url=".$back_url.$status."&error_type=".$error_type."&error_info=".$error_info."';</SCRIPT>";
exit;
}
function substr_cn($str,$strlen=10,$other=true) {
for($i=0;$i<$strlen;$i++)
if(ord(substr($str,$i,1))>0xa0) $j++;
if($j%2!=0) $strlen++;
$rstr=substr($str,0,$strlen);
if (strlen($str)>$strlen && $other) {$rstr.='..';}
return $rstr;
}
function getfilecontent($fileurl) {
if ($file = @fopen ($fileurl, "r")) {
$content='';
while (!feof ($file)) {
$line = fgets ($file);
$content.=$line;
}
fclose($file);
return $content;
} else return '';
}
function putfilecontent($filename,$content) {
$f=@fopen($filename,'w');
$d=@fwrite($f,$content);
@fclose($f);unset($content);
return $d;
}
function setopmlfile($filename,$data='',$ac="get") {
if ($ac=='get' and count($data)<>0) {
include_once("include/rss.inc");
$rss = new lastRSS;
$rs = $rss->Get($filename,1);
if ($data=='all') $d=$rs['items'];
else foreach ($rs['items'] as $i => $r) if (in_array($i,$data)) $d[]=$r;
return $d;
}
if ($ac=='del') {
include_once("include/rss.inc");
$rss = new lastRSS;
$rs = $rss->Get($filename,1);
//var_dump(array_diff(array_keys($rs['items']),$data));
$d=setopmlfile($filename,array_diff(array_keys($rs['items']),$data));
$filecontent=getfilecontent($filename);
$s=explode("<body>",$filecontent);
$s1=explode("</body>",$s[1]);
$html=$s[0]."<body></body>".$s1[1];
putfilecontent($filename,$html);
setopmlfile($filename,$d,"add");
//var_dump($data);
}
if ($ac=='add') {
if (!file_exists($filename)) {
$s[0]='<?xml version="1.0"?><head><title>365my RSS</title></head><opml>';
$s[1]='</body></opml>';
} else {
$html='';
$filecontent=getfilecontent($filename);
$s=explode("<body>",$filecontent);
}
if ($data<>'' ) foreach($data as $i => $d) {
foreach ($d as $j => $dd) $d[$j]=iconv("gb2312", "UTF-8",$dd);
$html.='<outline title="'.$d['title'].'" text="'.$d['text'].'" xmlUrl="'.$d['xmlUrl'].'" htmlUrl="'.$d['htmlUrl'].'"/>';
}
$filecontent=$s[0]."<body>".$html.$s[1];
return putfilecontent($filename,$filecontent);
}
}
//刷新资源
function update_resource(){
echo "<script>";
echo "parent.infomation.refresh_resource();";
echo "</script>";
}
//增加百分比公式
function add_percent($basenum,$percent,$grade){
return round($basenum * pow(1+$percent/100,$grade-1),0);
}
function add_workers($basenum1,$grade1){
return round($basenum1 * $grade1 * round(pow(1.1,$grade1-1),4),0);
}
function refresh_page(){
echo "<script>";
echo "parent.infomation.refresh_page();";
echo "</script>";
}
function refresh(){
echo "<script>";
echo "parent.infomation.refresh_self();";
echo "</script>";
}
//根据积分判断官位
function officer_name($p_score,$p_country){
include("../configs/Configs.php");//加载配置文件
$p_score_num=(int)($p_score/1000);
if($p_score_num<5) $officer_name=$officer_name[1];
elseif($p_score_num>=5 and $p_score_num<10) $officer_name=$officer_name[2];
elseif($p_score_num>=10 and $p_score_num<20) $officer_name=$officer_name[3];
elseif($p_score_num>=20 and $p_score_num<40) $officer_name=$officer_name[4];
elseif($p_score_num>=40 and $p_score_num<80) $officer_name=$officer_name[5];
elseif($p_score_num>=80 and $p_score_num<160) $officer_name=$officer_name[6];
elseif($p_score_num>=160 and $p_score_num<240) $officer_name=$officer_name[7];
elseif($p_score_num>=240 and $p_score_num<320) $officer_name=$officer_name[8];
elseif($p_score_num>=320 and $p_score_num<500) $officer_name=$officer_name[9];
elseif($p_score_num==500000) $officer_name=$officer_name[10];
else{//根据本国排名
include("class_mysql.php");//加载数据库类文件
$query_rank=$db->query("select u_id from player_info where `p_country`='".$p_country."' order by p_score desc limit 0,10");
$ranki=1;
while($rank_result=$db->fetch_array($query_rank)){
if($rank_result['u_id']==$_COOKIE['UserId']) {
if($ranki>=5 and $ranki<=10){
switch ($p_country){
case 1:{$officer_name=$officer_wei[1];break;}
case 2:{$officer_name=$officer_shu[1];break;}
case 3:{$officer_name=$officer_wu[1];break;}
}
}elseif($ranki<5 and $ranki>=2){
switch ($p_country){
case 1:{$officer_name=$officer_wei[2];break;}
case 2:{$officer_name=$officer_shu[2];break;}
case 3:{$officer_name=$officer_wu[2];break;}
}
}elseif($ranki==1){
switch ($p_country){
case 1:{$officer_name=$officer_wei[3];break;}
case 2:{$officer_name=$officer_shu[3];break;}
case 3:{$officer_name=$officer_wu[3];break;}
}
}
}
$ranki++;
}
}
return $officer_name;
}
/**
* Passport 加密函数
*
* @param string 等待加密的原字串
* @param string 私有密匙(用于解密和加密)
*
* @return string 原字串经过私有密匙加密后的结果
*/
function passport_encrypt($txt, $key) {
// 使用随机数发生器产生 0~32000 的值并 MD5()
srand((double)microtime() * 1000000);
$encrypt_key = md5(rand(0, 32000));
// 变量初始化
$ctr = 0;
$tmp = '';
// for 循环,$i 为从 0 开始,到小于 $txt 字串长度的整数
for($i = 0; $i < strlen($txt); $i++) {
// 如果 $ctr = $encrypt_key 的长度,则 $ctr 清零
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
// $tmp 字串在末尾增加两位,其第一位内容为 $encrypt_key 的第 $ctr 位,
// 第二位内容为 $txt 的第 $i 位与 $encrypt_key 的 $ctr 位取异或。然后 $ctr = $ctr + 1
$tmp .= $encrypt_key[$ctr].($txt[$i] ^ $encrypt_key[$ctr++]);
}
// 返回结果,结果为 passport_key() 函数返回值的 base65 编码结果
return base64_encode(passport_key($tmp, $key));
}
/**
* Passport 解密函数
*
* @param string 加密后的字串
* @param string 私有密匙(用于解密和加密)
*
* @return string 字串经过私有密匙解密后的结果
*/
function passport_decrypt($txt, $key) {
// $txt 的结果为加密后的字串经过 base64 解码,然后与私有密匙一起,
// 经过 passport_key() 函数处理后的返回值
$txt = passport_key(base64_decode($txt), $key);
// 变量初始化
$tmp = '';
// for 循环,$i 为从 0 开始,到小于 $txt 字串长度的整数
for ($i = 0; $i < strlen($txt); $i++) {
// $tmp 字串在末尾增加一位,其内容为 $txt 的第 $i 位,
// 与 $txt 的第 $i + 1 位取异或。然后 $i = $i + 1
$tmp .= $txt[$i] ^ $txt[++$i];
}
// 返回 $tmp 的值作为结果
return $tmp;
}
/**
* Passport 密匙处理函数
*
* @param string 待加密或待解密的字串
* @param string 私有密匙(用于解密和加密)
*
* @return string 处理后的密匙
*/
function passport_key($txt, $encrypt_key) {
// 将 $encrypt_key 赋为 $encrypt_key 经 md5() 后的值
$encrypt_key = md5($encrypt_key);
// 变量初始化
$ctr = 0;
$tmp = '';
// for 循环,$i 为从 0 开始,到小于 $txt 字串长度的整数
for($i = 0; $i < strlen($txt); $i++) {
// 如果 $ctr = $encrypt_key 的长度,则 $ctr 清零
$ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
// $tmp 字串在末尾增加一位,其内容为 $txt 的第 $i 位,
// 与 $encrypt_key 的第 $ctr + 1 位取异或。然后 $ctr = $ctr + 1
$tmp .= $txt[$i] ^ $encrypt_key[$ctr++];
}
// 返回 $tmp 的值作为结果
return $tmp;
}
/**
* Passport 信息(数组)编码函数
*
* @param array 待编码的数组
*
* @return string 数组经编码后的字串
*/
function passport_encode($array) {
// 数组变量初始化
$arrayenc = array();
// 遍历数组 $array,其中 $key 为当前元素的下标,$val 为其对应的值
foreach($array as $key => $val) {
// $arrayenc 数组增加一个元素,其内容为 "$key=经过 urlencode() 后的 $val 值"
$arrayenc[] = $key.'='.urlencode($val);
}
// 返回以 "&" 连接的 $arrayenc 的值(implode),例如 $arrayenc = array('aa', 'bb', 'cc', 'dd'),
// 则 implode('&', $arrayenc) 后的结果为 ”aa&bb&cc&dd"
return implode('&', $arrayenc);
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -