php 修复表与优化数据表
php 修复表与优化数据表
//--------------------------修复表
function Ebak_Rep($tablename,$dbname){
global $empire;
$dbname=RepPostVar($dbname);
$empire->query("use `$dbname`");
$count=count($tablename);
if(empty($count))
{
printerror("EmptyChangeTb","history.go(-1)");
}
for($i=0;$i<$count;$i++)
{
$sql1=$empire->query("REPAIR TABLE `$tablename[$i]`;");
}
printerror("RepairTbSuccess","ChangeTable.php?mydbname=$dbname");
}
//--------------------------忧化表
function Ebak_Opi($tablename,$dbname){
global $empire;
$dbname=RepPostVar($dbname);
$empire->query("use `$dbname`");
$count=count($tablename);
if(empty($count))
{
printerror("EmptyChangeTb","history.go(-1)");
}
for($i=0;$i<$count;$i++)
{
$sql1=$empire->query("OPTIMIZE TABLE `$tablename[$i]`;");
}
printerror("OptimizeTbSuccess","ChangeTable.php?mydbname=$dbname");
}
php 创建数据[crate database]与清空数据表
function Ebak_CreatDb($dbname,$dbchar=''){
global $empire,$phome_db_ver;
$dbname=RepPostVar($dbname);
if(!trim($dbname))
{
printerror("EmptyDbname","history.go(-1)");
}
$a="";
if($dbchar&&$phome_db_ver>='4.1')
{
$a=" DEFAULT CHARACTER SET ".$dbchar;
}
$sql=$empire->query("CREATE DATABASE IF NOT EXISTS `$dbname`".$a);
if($sql)
{
printerror("CreateDbSuccess","ChangeDb.php");
}
else
{printerror("DbError","history.go(-1)");}
}
//--------------------------清空表
function Ebak_EmptyTable($tablename,$dbname){
global $empire;
$dbname=RepPostVar($dbname);
$empire->query("use `$dbname`");
$count=count($tablename);
if(empty($count))
{printerror("EmptyChangeTb","history.go(-1)");}
for($i=0;$i<$count;$i++)
{
$sql1=$empire->query("TRUNCATE `".$tablename[$i]."`;");
}
printerror("TruncateTbSuccess","ChangeTable.php?mydbname=$dbname");
}
php 域名转发程序是我从其它地方看到了,通过xml与php交换实现的,下面我们来看看源文件吧。
<?xml version="1.0" encoding="utf-8"?>
<urls>
<num>1</num>
<url id="1">
<domain>test.domain.com</domain>
<to>http://www.111cn.net/to>
</url>
</urls>
index.php文件。
<?php
/*
域名伪跳转方案
By IVershuo.cn
*/
header("content-type:text/html; charset=utf-8");
$xml = simplexml_load_file("url.xml"); //xml文件路径
$to = 'http://www.111cn.net'; //默认跳转地址
foreach ($xml as $key => $value) {
if($value->domain == $_SERVER['SERVER_NAME']) {
$to = $value->to;
break;
}
}
header('Location: '.$to);
?>
处理文件
<?php
/*
域名伪跳转方案,域名跳转配置脚本
###注意:没设置验证可配置,使用时请修改该文件名和xml文件名!!!
By IVershuo.cn
*/
$xmlFile = 'url.xml'; //xml文件的路径
$xml = simplexml_load_file($xmlFile);
$num = $xml->num[0];
if (@$_POST['domain'] && $_POST['to']) {
$xmlUrl = $xml->addChild('url');
$xmlUrl->addAttribute('id',$num+=1);
$xmlUrl->addChild('domain',$_POST['domain']);
$xmlUrl->addChild('to',$_POST['to']);
$xml->num[0] = $num;
}
if (@$_GET['del']) {
removeNode($xml, "//url[@id='".$_GET['del']."']", 'all');
$xml->num[0] = $num;
}
$sp = fopen($xmlFile,"wb");
fwrite($sp,$xml->asXML());
fclose($sp);
function removeNode($xml, $path, $multi='one'){
$result = $xml->xpath($path);
# for wrong $path
if (!isset($result[0])) return false;
switch ($multi) {
case 'all':
$errlevel = error_reporting(E_ALL & ~E_WARNING);
foreach ($result as $r) unset ($r[0]);
error_reporting($errlevel);
return true;
case 'child':
unset($result[0][0]);
return true;
case 'one':
if (count($result[0]->children())==0 && count($result)==1) {
unset($result[0][0]);
return true;
}
default:
return false;
}
}
echo '<?xml version="1.0" encoding="utf-8"?>'."n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn" lang="zh-cn">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>域名添加</title>
<meta name="author" content="阿肆|IVershuo.cn" />
<style type="text/css">
label {display:block;margin:10px 0;}
input {width:300px;}
label span {color:#666;}
</style>
<script type="text/javascript" src=""></script>
</head>
<body>
<h1>域名转向添加</h1>
<div>
<form action="<?=$_SERVER ['PHP_SELF']?>" method="post">
<fieldset>
<legend>域名添加</legend>
<label for="domain">
域名:
http://<input type="text" name="domain" id="domain" />
<span>不用加“http://”</span>
</label>
<label for="to">
转向:
<input type="text" name="to" id="to" value="http://" />
<span>前面添加“http://”或“https://”等</span>
</label>
<button type="submit">提交</button>
</fieldset>
</form>
</div>
<div>
<ul id="listed">
<?php
$i=0;
foreach ($xml as $key => $value) {
if($key == 'url') {
echo '<li><em>http://'.$value->domain.'</em>跳转到<a href="'.$value->to.'">'.$value->to.'</a> <a href="'.$_SERVER ['PHP_SELF'].'?del='.$xml->url[$i]['id'].'">>删除<</a></li>';
$i++;
}
}
?>
<script type="text/javascript">
var li=document.getElementById('listed').getElementsByTagName('li');
for (var i=0,l=li.length;i<l ;i++ ) {
li[i].getElementsByTagName('a')[1].onclick=function () {
var u = this.parentNode.getElementsByTagName('em')[0].innerHTML;
if (confirm ('确定要删除 '+u+' 的转向?')) {
return true;
} else {
return false;
}
}
}
</script>
</ul>
</div>
</body>
</html>
<?php function ff_page($content,$page)
{
global $expert_id;
$PageLength = 2000; //每页字数
$CLength = strlen($content);
$PageCount = floor(($CLength / $PageLength)) + 1; //计算页数
$PageArray=array();
$Seperator = array("n","r","。","!","?",";",",","”","'"); //分隔符号
//echo "页数:".$PageCount."<br>";
//echo "长度:".$CLength."<br><br><br>";
//strpos() 函数返回字符串在另一个字符串中第一次出现的位置
if($CLength<$PageLength)
{
echo $content;
}else{
$PageArray[0]=0;
$Pos = 0;
$i=0;
//第一页
for($j=0;$j<sizeof($Seperator);$j++)
{
//echo $Seperator[$j];
$Pos=strpos($content,$Seperator[$j],$PageArray[$i]+1900);
while($Pos > 0 && $Pos < ($i+1)*$PageLength && $Pos > $i*$PageLength )
{
$PageArray[$i] = $Pos ;
$Pos = strpos($Pos+$PageLength,$content,$Seperator[$j]) ;
}
if($PageArray[$i]>0)
{
$j = $j + sizeof($Seperator) + 1;
}
}
//---
for($i=1;$i<$PageCount-1;$i++){
for($j=0;$j<sizeof($Seperator);$j++)
{
//echo $Seperator[$j];
$Pos=strpos($content,$Seperator[$j],$PageArray[$i-1]+1900);
while($Pos > 0 && $Pos < ($i+1)*$PageLength && $Pos > $i*$PageLength )
{
$PageArray[$i] = $Pos ;
$Pos = strpos($Pos+$PageLength,$content,$Seperator[$j]) ;
}
if($PageArray[$i]>0)
{
$j = $j + sizeof($Seperator) + 1;
}
}
}
//--最后一页
$PageArray[$PageCount-1]=$CLength;
//$page=2;
if($page==1)
{
$output=substr($content,0,$PageArray[$page-1]+2);
}
if($page>1 && $page<=$PageCount)
{
$output=substr($content,$PageArray[$page-2]+2,$PageArray[$page-1]-$PageArray[$page-2]);
$output=" (上接第".($page-1)."页)n".$output;
}
echo str_replace("n","<br> ",$output);
//if($page==$PageCount)
//return $output=substr($content,$PageArray[$page-2]+2,$PageArray[$page-1]-$PageArray[$page-2]);
if($PageCount>1)
{
echo "<br><br><br><center>";
echo "<font color='ff0000'>".$page."</font>/".$PageCount." 页 ";
if($page>1)
echo "<a href=$PHP_SELF?expert_id=$expert_id&page_t=".($page-1).">上一页</a> ";
else
echo "上一页 ";
for($i=1;$i<=$PageCount;$i++)
{
echo "<a href=$PHP_SELF?expert_id=$expert_id&page_t=".$i.">[".$i."]</a> ";
}
if($page<$PageCount)
echo " <a href=$PHP_SELF?expert_id=$expert_id&page_t=".($page+1).">下一页</a> ";
else
echo " 下一页 ";
echo "</center>";
}
}
}?>
<?php
$content1=''测试文字,尽量长一些,www.111cn.net";
$current=$_REQUEST['page_t'];
$result=ff_page($content1,$current);
echo $result;
?>
<?php
/**
*通过phpmailer发送qq邮件
*@author ray
*@since 2009-08-07
*/
define('__DEBUG__', false);
define('__PSW_FILE__', dirname(__FILE__) . '/smtp.dat');
define('SLEEPING_EMAIL', dirname(__FILE__) . "/sleepMail.dat");//休眠的email
define('SLEEPING_TIME', 1800);//休眠多长时间,以秒为单位
define('FILE_APPEND', 1);
if (!function_exists('file_put_contents')) {
function file_put_contents($n, $d, $flag = false) {
$mode = ($flag == FILE_APPEND || strtoupper($flag) == 'FILE_APPEND') ? 'a' : 'w';
$f = @fopen($n, $mode);
if ($f === false) {
return 0;
} else {
if (is_array($d)) $d = implode($d);
$bytesWritten = fwrite($f, $d);
fclose($f);
return $bytesWritten;
}
}
}
$errorNo = 0;
$errorMsg = '';
$currTime = time();
$unuseMails = array();
//收件人和邮件标题和邮件内容
$to = isset($argv[1]) ? $argv[1] : "" ;
$subject = isset($argv[2]) ? $argv[2] : "";
$mailFile = isset($argv[3]) ? $argv[3] : "" ;
if (__DEBUG__) {
echo "
file:$mailFile to:$to subject:$subjectrn";
}
if (empty($mailFile) || empty($to) || empty($subject)) {
$errorNo = 1;
$errorMsg = "参数不全";
}
//加载不可用的email列表
if (!$errorNo) {
if (file_exists(SLEEPING_EMAIL)) {
$sleepMails = file(SLEEPING_EMAIL);
if (!empty($sleepMails)) {
foreach($sleepMails as $sleepMail) {
//解析
if (false !== strpos($sleepMail, '|')) {
$tmp = explode('|', $sleepMail);
if (isset($tmp[0]) && isset($tmp[1])) {
$mail = trim($tmp[0]);
$time = trim($tmp[1]);
//是否可用
if ( ($currTime - $time )< SLEEPING_TIME) {
$unuseMails[] = $mail;
}
}
}
}
}
}
}
if (!$errorNo) {
//随机加载smtp服务器和smtp用户名和密码
$info = file(__PSW_FILE__);
$len = count($info);
do {
$rnd = mt_rand(0, $len - 1);
$line = isset($info[$rnd]) ? $info[$rnd] : "";
if (false !== strpos($line, '|')) {
$tmp = explode('|', $line);
if (isset($tmp[0]) && isset($tmp[1]) && isset($tmp[2])) {
$smtpServer = trim($tmp[0]);
$fromMail = trim($tmp[1]);
$psw = trim($tmp[2]);
$smtpUserName = substr($fromMail, 0, strrpos($fromMail, '@'));
}
}
}while (in_array($fromMail, $unuseMails));//如果在不可用的列表中,在次加载
if (!isset($smtpServer) || !isset($fromMail) || !isset($psw)) {
$errorNo = 2;
$errorMsg = "没找到发件人QQ信箱和密码";
}
}
if (!$errorNo && __DEBUG__) {
echo "smtp:$smtpServer from:$fromMail psw:$psw user:$smtpUserNamern";
}
if (!$errorNo) {
//通过phpmailer连接smtp服务器发信
require(dirname(__FILE__) . "/phpmailer/class.phpmailer.php");
require(dirname(__FILE__) . "/phpmailer/class.smtp.php");
$mail = new PHPMailer();
$body = $mail->getFile($mailFile);
$body = eregi_replace("[]",'',$body);
//charset
$mail->CharSet = "GB2312";
//$mail->SMTPDebug = 2;//用于显示具体的smtp错误
$mail->IsSMTP();
$mail->SMTPAuth = true;
if ("smtp.qq.com" == trim($smtpServer)) {
$mail->Username = $fromMail;
} else {
$mail->Username = $smtpUserName;
}
$mail->Password = $psw;
$mail->Host = $smtpServer;
$mail->From = $fromMail;
$mail->FromName = "晴天网络";
$mail->IsHTML(true);
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->Body = $body;
if (!$mail->Send()) {
// echo "Message could not be sent. ";
$errorNo = 3;
$errorMsg = $mail->ErrorInfo;
} else {
echo "
Send to $to success use $fromMailrn";
exit;
}
}
if (3 == $errorNo) {
//记录信息,该信息地址休眠N分钟
$content = "$fromMail|" . time() . "rn";//email|当前时间戳
file_put_contents(SLEEPING_EMAIL, $content, FILE_APPEND);
}
echo "
Error No($errorNo) " . $errorMsg . "rn";
exit;
?>
相关文章
- 本文给大家分享C#连接SQL数据库和查询数据功能的操作技巧,本文通过图文并茂的形式给大家介绍的非常详细,需要的朋友参考下吧...2021-05-17
- 最基础的对数据的增加删除修改操作实例,菜鸟们收了吧...2013-09-26
- 这篇文章主要介绍了解决Mybatis 大数据量的批量insert问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-01-09
Antd-vue Table组件添加Click事件,实现点击某行数据教程
这篇文章主要介绍了Antd-vue Table组件添加Click事件,实现点击某行数据教程,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-17- 这篇文章主要介绍了详解如何清理redis集群的所有数据,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-18
- 这篇文章主要介绍了vue 获取到数据但却渲染不到页面上的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-11-19
- Multipart/form-data是文件上传或数据提交时会用到了,在php中Multipart/form-data是有安全bug的,下面我们来看看如何修复Multipart/form-data的bug吧. 今天在乌云...2016-11-25
- 在php中解析xml文档用专门的函数domdocument来处理,把json在php中也有相关的处理函数,我们要把数据xml 数据存到一个数据再用json_encode直接换成json数据就OK了。...2016-11-25
- 这篇文章主要介绍了mybatis-plus 处理大数据插入太慢的解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-12-18
- 这篇文章主要介绍了postgresql数据添加两个字段联合唯一的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-04
Vue生命周期activated之返回上一页不重新请求数据操作
这篇文章主要介绍了Vue生命周期activated之返回上一页不重新请求数据操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-07-26- 关于mysql效率优化一般通过以下两种方式定位执行效率较低的sql语句。通过慢查询日志定位那些执行效率较低的 SQL 语句,用 --log-slow-queries[=file_name] 选项启动时, mysqld 会 写一个包含所有执行时间超过 long_quer...2015-11-08
- 过了这么久,discuz论坛的问题还是困扰着很多网友,其实从各论坛里看到的问题总结出来,很关键的一点都是因为没有将数据表引擎转成InnoDB导致的,discuz在并发稍微高一点的环境下就表现的非常糟糕,产生大量的锁等待,这时候如果...2015-11-24
- java开发的Android应用,性能一直是一个大问题,,或许是Java语言本身比较消耗内存。本文我们来谈谈Android 性能优化之MemoryFile文件读写。 Android匿名共享内存对外A...2016-09-20
- 这篇文章主要介绍了解决vue watch数据的方法被调用了两次的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-07
- MySQL是一个功能强大的开源数据库。随着越来越多的数据库驱动的应用程序,人们一直在推动MySQL发展到它的极限。这里是101条调节和优化 MySQL安装的技巧。一些技巧是针对特定的安装环境的,但这些思路是通用的。我已经把...2013-09-11
- 这篇文章主要介绍了Angular性能优化之第三方组件和懒加载技术,对性能优化感兴趣的同学,可以参考下...2021-05-11
- 这篇文章主要介绍了c# socket网络编程,server端接收,client端发送数据,大家参考使用吧...2020-06-25
- 这篇文章主要介绍了JavaScript提高网站性能优化的建议(二)的相关资料,需要的朋友可以参考下...2016-07-29
- 这篇文章主要介绍了vue 数据(data)赋值问题的解决方案,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-29