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

📄 index.php

📁 MYSQL全系列自导入数据库备份程序 v1.0 支持MYSQL4.1
💻 PHP
📖 第 1 页 / 共 3 页
字号:
<?PHP
//配置部分: 
//注意,如果您没有在后面的注释的地方加上管理员身份验证程序,
//请不要配置正确的数据库用户名和密码!
//采用默认配置运行,程序会给出表单你填写的。

$db_host="localhost";    //数据库服务器
$db_username="root";     //数据库用户名
$db_password="";         //数据库密码
$db_dbname="";          //选择的数据库

//兼容低版本PHP
function requestValues(){
	return ' if(!isset($_POST)){ $_POST = $HTTP_POST_VARS; $_GET = $HTTP_GET_VARS; $_SERVER = $HTTP_SERVER_VARS;} ';
}

eval(requestValues());

$_POST["frametopheight"]=90;  //FrameTop 的高

define("VERSION","4.0"); //版本

error_reporting(1);
@set_time_limit(0);

function num_bitunit($num){
  $bitunit=array(' B',' KB',' MB',' GB');
  for($key=0;$key<count($bitunit);$key++){
	if($num>=pow(2,10*$key)-1){ //1023B 会显示为 1KB
	  $num_bitunit_str=(ceil($num/pow(2,10*$key)*100)/100)." $bitunit[$key]";
	}
  }
  return $num_bitunit_str;
}

//frame 分开标题
function frameset_html(){
	global $_POST;
	return "if(!\$_GET[framename]){
		echo \"<html>
		<head> <meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
		<title>自导入数据库备份程序 — Powerd By faisun Edit by HaierSpI</title>
		</head>
		<frameset rows='$_POST[frametopheight],*,0' frameborder='NO' border='0' framespacing='0' name='myframeset'>
			<frame src='\$_SERVER[PHP_SELF]?action=topframe&framename=topframe' name='topFrame' scrolling='NO' noresize>
			<frame src='\$_SERVER[PHP_SELF]?\$_SERVER[QUERY_STRING]&framename=main' name='mainFrame1'>
			<frame src='about:blank' name='mainFrame2'>  
		</frameset>
		<BODY></BODY>
		</html>\";
		exit;
	}";
}

function postvars_function(){
	return '
	function fsql_StrCode($string,$action="ENCODE"){
		global $_SERVER;
		if($string=="") return "";
		if($action=="ENCODE") $md5code=substr(md5($string),8,10);
		else{
			$md5code=substr($string,-10); 
			$string=substr($string,0,strlen($string)-10); 
		}
		$key = md5($md5code.$_SERVER["HTTP_USER_AGENT"].filemtime($_SERVER["SCRIPT_FILENAME"]));
		$string = ($action=="ENCODE"?$string:base64_decode($string));
		$len = strlen($key);
		$code = "";
		for($i=0; $i<strlen($string); $i++){
			$k = $i%$len;
			$code .= $string[$i]^$key[$k];
		}
		$code = ($action == "DECODE" ? (substr(md5($code),8,10)==$md5code?$code:NULL) : base64_encode($code)."$md5code");
		return $code;
	}
	if($_POST[faisunsql_postvars]){
		if($faisunsql_postvars=unserialize(fsql_StrCode($_POST[faisunsql_postvars],"DECODE"))){
			foreach($faisunsql_postvars as $key=>$value){
				if(!isset($_POST[$key])) $_POST[$key] = $value;
			}
		}else{ die("<script language=\'JavaScript\'>alert(\'由于文档更改,提交信息已丢失,需要重新开始.\');</script>"); }
		unset($_POST[faisunsql_postvars],$faisunsql_postvars,$key,$value);
	}';	
}

eval(frameset_html().postvars_function());

if($_POST["totalsize"]){
	$totalsize_chunk=num_bitunit($_POST["totalsize"]);
}

//css 样式定义
function csssetting(){
  return "<style type='text/css'>
	<!--
	body, td, input, a{
		color:#985b00;
		font-family: '宋体';
		font-size: 9pt;
	}
	body, td, a{
		line-height:180%; 
	}
	.tabletitle{
		color:#FFFFFF;
		background-color:#FF6600;
	}
	.tabledata{
		background-color:#FFEECC;
	}
	.tabledata_on{
		background-color:#FFFFCC;
	}	
	input, .borderdiv {
		border:1px inset;
	}
	-->
	</style>";
}

//各页相同的页面头
function fheader(){
	global $_POST;
	$str = fsql_StrCode(serialize($_POST),"ENCODE");
	echo "<html>
	<head> 
	<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
	<title>自导入数据库备份程序 — Powerd By faisun Edit by HaierSpI</title>
	".csssetting()."
	</head><body link='#0000FF' vlink='#0000FF' alink='#0000FF' bgcolor='#FFFFFF'>
	<center><script language='Javascript'>document.doshowmywin=1;</script>
	<form name='myform' method='post' action=''><input type='hidden' name='faisunsql_postvars' value='".$str."'>";
}

function showmywin_script(){
	global $_POST;
	return "<script language='Javascript'>
	function showmywin(){
		if(!document.doshowmywin) return;
		if(top.myframeset&&this.window.name=='mainFrame1'){
			top.myframeset.rows='$_POST[frametopheight],*,0';
		}
		if(top.myframeset&&this.window.name=='mainFrame2'){
			top.myframeset.rows='$_POST[frametopheight],0,*';
		}
	}
	document.body.onload=showmywin;
	</script>";
}
//各页相同的页面尾
function ffooter(){
	echo "<div id='pageendTag'></div></form>
	<br><br><font color=red><b>AD位 PHP主力技术论坛:<a href='http://www.phpso.com' target='_blank'>PHPSO.COM</a></b> </font><br>
	<B>	<font color=red>QQ群:6116767</font></B>
	<B>FaisunSQL自导入数据库备份程序 V".VERSION." HaierSpI 修改版</B><br>

	</center>".showmywin_script()."</body></html>";
}

//开始说明表格
function tabletext($ttext="",$twidth=400){
	return "<table width='$twidth' border='0' cellspacing='1' cellpadding='3' align=center><tr><td>$ttext</td></tr></table><br>\r\n";
}

//开始一个表格
function tablestart($ttitle="",$twidth=400){
	return "<table width='1' border='0' cellspacing='0' cellpadding='0' align=center class='tabletitle'>
	<tr><td class='tabletitle'><strong>&nbsp;$ttitle</strong></td></tr> <tr><td>
	<table width='$twidth' border='0' cellspacing='1' cellpadding='2' align=center>";
}

//插入数据到表格
function tabledata($data,$widths=""){
	$pdata=explode("|",$data);
	$pwidths=explode("|",$widths);
	$str="<tr class='tabledata' onmouseover='this.className=\"tabledata_on\";' onmouseout='this.className=\"tabledata\";'>\r\n";
	for(@reset($pdata);@list($key,$val)=@each($pdata);){
		$str.="\t<td style='padding-left:4px' ".(intval($pwidths[$key])?"width='$pwidths[$key]'":"")." nowrap>$pdata[$key]</td>\r\n";
	}
	$str.="</tr>\r\n";
	return $str;
}

//结束一个表格
function tableend(){
	return "</table></td></tr></table><BR>\r\n";
}

//按钮样式
function fbutton($type="submit",$name="Submit",$value="确定",$script="",$return=0){
	$str="<input type='$type' name='$name' value='$value' class='tabletitle' style='border:3px double #FF6600' $script> ";
	if($return) return $str;else echo $str;
}

//topFrame
if($_GET["action"]=="topframe"&&$_GET["framename"]=="topframe"){
	fheader();
	echo "<center><a href='http://www.phpso.com' target='_blank'><img src='faisunsql_files/faisunsqllogo.gif' border=0 width=300 height=71></a></center>";
	echo "</font></center></body></html>";
	exit;
}

//说明文档
if($_GET["action"]=="readme"){
	fheader();
	echo tablestart("说明文档");
	echo tabledata(implode('',file("faisunsql_files/readme.htm")));
	echo tableend();
	ffooter();
	exit;
}

/* 
如果您在开头配置部分填写了正确的配置,
您可以在这里加上管理员身份验证,
并把下面声明常量的语句用在代码中:
define("IS_ADMIN","yes");  //用于检验是否加了管理员身份验证代码。
*/

if(!isset($_POST[dosubmit])){
	$_POST["db_host"]=$db_host;
	$_POST["db_username"]=$db_username;
	$_POST["db_password"]=$db_password;
	$_POST["db_dbname"]=$db_dbname;
	$_POST["db_code"]=$db_code;
}

// 配置表单
if(!@mysql_connect($_POST[db_host],$_POST[db_username],$_POST[db_password])||!@mysql_select_db($_POST[db_dbname])){
	fheader();
	if(isset($_POST['finByte']) and isset($_POST['db_dbname'])){
		echo "连接数据库超时,请<a href='javascript:submitme();'>刷新重试</a>.<font id='timeescapepls'>10</font>秒后将自动重试.<BR>也可能是配置不对,请检查您的配置.<BR>";
		echo "
		<script language='JavaScript'>
		document.doshowmywin=0;
		retryTime=10;
		function timeescape(){
			if(!retryTime) return;
			timeescapepls.innerHTML=retryTime--;
		}setInterval('timeescape()',1000);
		function submitme(){
			for(i=myform.elements.length-1;i>=0;i--){if(myform.elements[i].name==\"action\")break;}
			myform.elements[i].value=\"databackup\";
			myform.submit();
		}
		setTimeout('submitme()',retryTime*1000);
		</script>";
	}
	else if(isset($_POST[dosubmit])){
		echo "<script language='JavaScript'>alert('连接数据库错误,请检查您的配置.');</script>";
	}
	echo tabletext("输入正确的配置以连接数据库。<br> 如果无法连接数据库,请联系您的主机管理员以获得正确配置值。");
	echo tablestart("请检查您的配置");
	echo tabledata("服务器主机:|<input name='db_host' value='$_POST[db_host]' type='text'>");
	echo tabledata("要导出的数据库:|<input name='db_dbname' value='$_POST[db_dbname]' type='text'>");
	echo tabledata("数据库用户名:|<input name='db_username' value='$_POST[db_username]' type='text'>");
	echo tabledata("数据库密码:|<input name='db_password' value='$_POST[db_password]' type='password'>");
	echo tabledata("数据库编码(MYSQL低于4.1本项无效):|<input name='db_code' value='$_POST[db_code]' type='text'>");
	echo tableend();
	fbutton('submit','dosubmit','连接');
	fbutton('reset','doreset','重置');
	ffooter();
	//新版本检测
	echo "<script src='http://www.softpure.com/soft/faisunsql/version.php?v=".VERSION."'></script>";	
	exit;
}
//mysql_query("SET NAMES gb2312;");
if (mysql_get_server_info()> '4.1'){
	global $db_codeset,$_POST;
mysql_query("SET NAMES `GBK`");
	$db_codeset = $_POST["db_code"];
}
if(!defined("IS_ADMIN") and !isset($_POST['db_dbname'])){die("您在程序开头部分填写了正确的配置,但没有加上任何管理员身份验证代码。为了安全,请不要配置正确的数据库用户名和密码!");}

//选择要备份的数据表
if (!isset($_POST['action'])){
	$currow=mysql_fetch_array(mysql_query("select version() as v"));
	$_POST['mysql_version']=$currow['v'];
	fheader();
	echo tabletext("以下列出的是该数据库中所有的数据表。<br>默认情况下全部导出,您也可以选择只导出其中一部分表。",500);
	echo tablestart("请选择要备份的数据表 &nbsp; (当前数据库版本: $_POST[mysql_version])",500);
	echo tabledata("<center><B><a href='#' onclick='selrev();return false;'>[反选]</a></B></center>|<strong>表名</strong>|<strong>注释</strong>|<strong>记录数</strong>|<strong>大小</strong>","10%|30%|30%|17%|23%");
	$query=mysql_query("SHOW TABLE STATUS");
	while ($currow=mysql_fetch_array($query)){
		echo tabledata("<center><input name='fsqltable[{$currow[Name]}]' id='fsqltable_$currow[Name]' type='checkbox' value='".($currow[Data_length]+$currow[Index_length]).",".$currow[Avg_row_length]."' checked onclick='getsize()'></center>|<label for='fsqltable_$currow[Name]'>$currow[Name]</label>|$currow[Comment]|$currow[Rows]|".num_bitunit($currow[Data_length]+$currow[Index_length])."");
	}
	echo tabledata("<center><B><a href='#' onclick='selrev();return false;'>[反选]</a></B></center>|<B>目前选择表的总大小:</B>|&nbsp;|&nbsp;|<B><label id='totalsizetxt'></label></B>");
	echo tableend();
	echo "<script language='JavaScript'>
	<!--
	  function selrev() {
		with(myform) {
			for(i=0;i<elements.length;i++) {
				thiselm = elements[i];
				if(thiselm.name.match(/fsqltable\[\w+\]/))
					thiselm.checked = !thiselm.checked;
			}
		}
		getsize();
	  }
	
	  function num_bitunit(num){
		 var bitunit=new Array(' B',' KB',' MB',' GB');
		 for(key=0;key<bitunit.length;key++){
		   if(num>=Math.pow(2,10*key)-1){ //1023B 会显示为 1KB
			  num_bitunit_str=(Math.ceil(num/Math.pow(2,10*key)*100)/100)+' '+bitunit[key];
		   }	 
		 }
		 return num_bitunit_str;
	  }
	
	  function getsize(){
		var ts=0;
		with(document.myform) {
			for(i=0;i<elements.length;i++) {
				thiselm = elements[i];
				if(thiselm.name.match(/fsqltable\[\w+\]/))
					ts += parseInt(thiselm.value);
			}
			totalsizetxt.innerHTML=num_bitunit(ts);
		}
	  }
	  getsize();
	-->
	</script>
	<input name='action' type='hidden' id='action' value='selecttype'>";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -