⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connect.php

📁 一、超强系统模型扩展功能 EmpireCMS卓越之处在于:不仅提供了网站管理功能
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?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]."&nbsp;".$num."&nbsp;".$fun_r[totalrecorde]."&nbsp;&nbsp;";
	$PHP_SELF=$_SERVER['PHP_SELF'];
	if($start!=0)
	{
		$old_start=$start-$pagetotal;
		$returnstr.="&nbsp;&nbsp;<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.="&nbsp;&nbsp;".$is_1.$pagenum.$is_2;
	}
	if($total_start!=($start/$pagetotal+1)&&$num!=0)
	{
		$new_start=$start+$pagetotal;
		$returnstr.="&nbsp;&nbsp;<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 + -