?? connect.php
字號:
<?php
error_reporting(E_ALL ^ E_NOTICE);
define('InEmpireCMS',TRUE);
$addgethtmlpath="";
$editor=0;
function db_connect(){
global $phome_db_server,$phome_db_username,$phome_db_password,$phome_db_dbname,$phome_db_port,$phome_db_char,$phome_use_dbver;
$dblocalhost=$phome_db_server;
//端口
if($phome_db_port)
{
$dblocalhost.=":".$phome_db_port;
}
$link=@mysql_connect($dblocalhost,$phome_db_username,$phome_db_password);
if(!$link)
{
echo"Cann't connect to DB!";
exit();
}
//編碼
if($phome_use_dbver>='4.1')
{
if($phome_db_char)
{
@mysql_query("SET names '".$phome_db_char."';");
}
if($phome_use_dbver>='5.0')
{
@mysql_query("SET sql_mode=''");
}
}
@mysql_select_db($phome_db_dbname);
return $link;
}
//設置編碼
function DoSetDbChar($dbchar){
if($dbchar)
{
@mysql_query("set names '".$dbchar."';");
}
}
function db_close(){
global $link;
@mysql_close($link);
}
//設置COOKIE
function esetcookie($var,$val,$life=0){
global $phome_cookiedomain,$phome_cookiepath,$phome_cookievarpre;
return setcookie($phome_cookievarpre.$var,$val,$life,$phome_cookiepath,$phome_cookiedomain);
}
//返回cookie
function getcvar($var){
global $phome_cookievarpre;
$tvar=$phome_cookievarpre.$var;
return $_COOKIE[$tvar];
}
//錯誤提示
function printerror($error="",$gotourl="",$ecms=0,$noautourl=0,$novar=0){
global $empire,$editor,$ecmslang,$public_r;
if($editor==1){$a="../";}
elseif($editor==2){$a="../../";}
elseif($editor==3){$a="../../../";}
else{$a="";}
if(strstr($gotourl,"(")||empty($gotourl))
{
$gotourl_js="history.go(-1)";
$gotourl="javascript:history.go(-1)";
}
else
{$gotourl_js="self.location.href='$gotourl';";}
if(empty($error))
{$error="DbError";}
if($ecms==9)//彈出對話框
{
@include $a.LoadLang("pub/q_message.php");
$error=empty($novar)?$qmessage_r[$error]:$error;
echo"<script>alert('".$error."');".$gotourl_js."</script>";
@db_close();
$empire=null;
exit();
}
if($ecms==0)
{
@include $a.LoadLang("pub/message.php");
$error=empty($novar)?$message_r[$error]:$error;
@include($a."message.php");
}
else
{
@include $a.LoadLang("pub/q_message.php");
$error=empty($novar)?$qmessage_r[$error]:$error;
@include($a."../message/index.php");
}
@db_close();
$empire=null;
exit();
}
//ajax錯誤提示
function ajax_printerror($error='isfail'){
global $empire;
echo $error;
@db_close();
$empire=null;
exit();
}
//編碼轉換
function DoIconvVal($code,$targetcode,$str,$inc=0){
global $editor;
if($editor==1){$a="../";}
elseif($editor==2){$a="../../";}
elseif($editor==3){$a="../../../";}
else{$a="";}
if($inc)
{
@include_once("doiconv.php");
}
$iconv=new Chinese($a);
$str=$iconv->Convert($code,$targetcode,$str);
return $str;
}
//模板表轉換
function GetTemptb($temptb){
global $public_r,$ecmsdeftempid,$dbtbpre;
if(!empty($ecmsdeftempid))
{
$tempid=$ecmsdeftempid;
}
else
{
$tempid=$public_r['deftempid'];
}
if(!empty($tempid)&&$tempid!=1)
{
$en="_".$tempid;
}
return $dbtbpre.$temptb.$en;
}
//返回操作模板表
function GetDoTemptb($temptb,$gid){
global $dbtbpre;
if(!empty($gid)&&$gid!=1)
{
$en="_".$gid;
}
return $dbtbpre.$temptb.$en;
}
//返回當前使用模板組ID
function GetDoTempGid(){
global $ecmsdeftempid,$public_r;
if($ecmsdeftempid)
{
$gid=$ecmsdeftempid;
}
elseif($public_r['deftempid'])
{
$gid=$public_r['deftempid'];
}
else
{
$gid=1;
}
return $gid;
}
//導入語言包
function LoadLang($file){
global $ecmslang;
return "../data/language/".$ecmslang."/".$file;
}
//取得IP
function egetip(){
if(getenv('HTTP_CLIENT_IP')&&strcasecmp(getenv('HTTP_CLIENT_IP'),'unknown'))
{
$ip=getenv('HTTP_CLIENT_IP');
}
elseif(getenv('HTTP_X_FORWARDED_FOR')&&strcasecmp(getenv('HTTP_X_FORWARDED_FOR'),'unknown'))
{
$ip=getenv('HTTP_X_FORWARDED_FOR');
}
elseif(getenv('REMOTE_ADDR')&&strcasecmp(getenv('REMOTE_ADDR'),'unknown'))
{
$ip=getenv('REMOTE_ADDR');
}
elseif(isset($_SERVER['REMOTE_ADDR'])&&$_SERVER['REMOTE_ADDR']&&strcasecmp($_SERVER['REMOTE_ADDR'],'unknown'))
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return preg_replace("/^([\d\.]+).*/", "\\1",$ip);
}
//返回地址
function DoingReturnUrl($url,$from=''){
if(empty($from))
{
return $url;
}
elseif($from==9)
{
$from=$_SERVER['HTTP_REFERER']?$_SERVER['HTTP_REFERER']:$url;
}
return $from;
}
//參數處理函數
function RepPostVar($val){
if($val!=addslashes($val))
{
exit();
}
$val=str_replace(" ","",$val);
$val=str_replace("%20","",$val);
$val=str_replace("*","",$val);
$val=str_replace("'","",$val);
$val=str_replace("\"","",$val);
$val=str_replace("/","",$val);
$val=str_replace(";","",$val);
$val=addslashes(stripSlashes($val));
return $val;
}
//參數處理函數2
function RepPostVar2($val){
if($val!=addslashes($val))
{
exit();
}
$val=str_replace("%20","",$val);
$val=str_replace("*","",$val);
$val=str_replace("'","",$val);
$val=str_replace("\"","",$val);
$val=str_replace("/","",$val);
$val=str_replace(";","",$val);
$val=addslashes(stripSlashes($val));
return $val;
}
//處理提交字符
function RepPostStr($val){
$val=htmlspecialchars($val);
return $val;
}
//-------------------取得文件擴展名
function GetFiletype($filename){
$filer=explode(".",$filename);
$count=count($filer)-1;
return strtolower(".".$filer[$count]);
}
//取得文件名
function GetFilename($filename){
if(strstr($filename,"\\"))
{
$exp="\\";
}
else
{
$exp='/';
}
$filer=explode($exp,$filename);
$count=count($filer)-1;
return $filer[$count];
}
//---------------------------字符截取函數2
function sub($Modi_Str,$start,$length,$mode = false){
$n = 0;
for($i=0;$i<$start;$i++){
if(ord(substr($Modi_Str,$i,1))>0xa0){
if($mode){
$start++;
$i++;
}
$n++;
}
}
if(!$mode)$start = $start + $n%2;
$The_length = $start+$length;
for($i=$start;$i<$The_length;$i++){
if(ord(substr($Modi_Str,$i,1))>0xa0){
$The_Str.=substr($Modi_Str,$i,2);
$i++;
if($mode) $The_length++;
}else{
$The_Str.=substr($Modi_Str,$i,1);
}
}
return $The_Str;
}
//取得隨機數
function make_password($pw_length){
$low_ascii_bound=50;
$upper_ascii_bound=122;
$notuse=array(58,59,60,61,62,63,64,73,79,91,92,93,94,95,96,108,111);
while($i<$pw_length)
{
mt_srand((double)microtime()*1000000);
$randnum=mt_rand($low_ascii_bound,$upper_ascii_bound);
if(!in_array($randnum,$notuse))
{
$password1=$password1.chr($randnum);
$i++;
}
}
return $password1;
}
//取得隨機數(數字)
function no_make_password($pw_length){
$low_ascii_bound=48;
$upper_ascii_bound=57;
$notuse=array(58,59,60,61,62,63,64,73,79,91,92,93,94,95,96,108,111);
while($i<$pw_length)
{
mt_srand((double)microtime()*1000000);
$randnum=mt_rand($low_ascii_bound,$upper_ascii_bound);
if(!in_array($randnum,$notuse))
{
$password1=$password1.chr($randnum);
$i++;
}
}
return $password1;
}
//--------------------------------------分頁
function page1($num,$line,$page_line,$start,$page,$search){
global $fun_r;
$pagetotal=$line*$page_line;//所要顯示的總條數
$total=ceil(($num-$start)/$line);//取得總頁數
$total_start=ceil($num/$pagetotal);//取得總偏移數
$returnstr=$fun_r[totalrecord]." ".$num." ".$fun_r[totalrecorde]." ";
$PHP_SELF=$_SERVER['PHP_SELF'];
if($start!=0)
{
$old_start=$start-$pagetotal;
$returnstr.=" <a href=".$PHP_SELF."?page=0&start=".$old_start.$search." title='UP".$page_line."Pages'><font face=webdings>7</font></a>";
}
$pagestart=$start/$pagetotal*$page_line;//取得當前頁數
for($i=0;$i<$total&&$i<$page_line;$i++)
{
if($page==$i)
{$is_1="<b>[";$is_2="]</b>";}
else
{$is_1="<a href=".$PHP_SELF."?page=".$i."&start=".$start.$search.">";$is_2="</a>";}
$pagenum=$pagestart+$i+1;
$returnstr.=" ".$is_1.$pagenum.$is_2;
}
if($total_start!=($start/$pagetotal+1)&&$num!=0)
{
$new_start=$start+$pagetotal;
$returnstr.=" <a href=".$PHP_SELF."?page=0&start=".$new_start.$search." title='Next".$page_line."Pages'><font face=webdings>8</font></a>";
}
return $returnstr;
}
//時間轉換函數
function to_time($datetime){
if(strlen($datetime)==10)
{
$datetime.=" 00:00:00";
}
$r=explode(" ",$datetime);
$t=explode("-",$r[0]);
$k=explode(":",$r[1]);
$dbtime=mktime($k[0],$k[1],$k[2],$t[1],$t[2],$t[0]);
return $dbtime;
}
//時期轉日期
function date_time($time,$format="Y-m-d H:i:s"){
$threadtime=date($format,$time);
return $threadtime;
}
//格式化日期
function format_datetime($newstime,$format){
if($newstime=="0000-00-00 00:00:00")
{return $newstime;}
$time=to_time($newstime);
$newdate=date_time($time,$format);
return $newdate;
}
//時間轉換函數
function to_date($date){
$date.=" 00:00:00";
$r=explode(" ",$date);
$t=explode("-",$r[0]);
$k=explode(":",$r[1]);
$dbtime=@mktime($k[0],$k[1],$k[2],$t[1],$t[2],$t[0]);
return $dbtime;
}
//選擇時間
function ToChangeTime($time,$day){
$truetime=$time-$day*24*3600;
$date=date_time($truetime,"Y-m-d");
return $date;
}
//刪除文件
function DelFiletext($filename){
@unlink($filename);
}
//取得文件內容
function ReadFiletext($filepath){
$filepath=trim($filepath);
$htmlfp=@fopen($filepath,"r");
//遠程
if(strstr($filepath,"://"))
{
while($data=@fread($htmlfp,500000))
{
$string.=$data;
}
}
//本地
else
{
$string=@fread($htmlfp,@filesize($filepath));
}
@fclose($htmlfp);
return $string;
}
//寫文件
function WriteFiletext($filepath,$string){
global $public_r;
$string=stripSlashes($string);
$fp=@fopen($filepath,"w");
@fputs($fp,$string);
@fclose($fp);
if($public_r[filechmod]==1)
{}
else
{
@chmod($filepath,0777);
}
}
//寫文件
function WriteFiletext_n($filepath,$string){
global $public_r;
$fp=@fopen($filepath,"w");
@fputs($fp,$string);
@fclose($fp);
if($public_r[filechmod]==1)
{}
else
{
@chmod($filepath,0777);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -