<?
/*
// 作者:Mr.abcM
// 邮箱:42978632@qq.com
// 网站设计制作 空间域名销售
// 为您提供最具性价比的网络服务
*/
error_reporting(E_ALL);//错误报告 E_ALL开 0关
date_default_timezone_set('PRC');//中国时间
header('Content-Type: text/html; charset=UTF-8');//页面编码
//链接数据库
$dbfile = './sqlite#db.db';//数据库目录和名称
$db = sqlite_open($dbfile);//不存在则会自动创建
//如果数据库文件没有数据则创建数据库
if(!filesize($dbfile)){
//建立表和设置字段及类型
sqlite_query($db,'CREATE TABLE config(
name VARCHAR(50) NOT NULL,
pswd VARCHAR(32) NOT NULL,
pv VARCHAR(10) NOT NULL,
audit CHAR(1) NOT NULL,
size CHAR(2) NOT NULL,
info TEXT
)');
sqlite_query($db,'CREATE TABLE book(
id INTEGER PRIMARY KEY NOT NULL,
ip VARCHAR(12) NOT NULL,
time CHAR(10) NOT NULL,
audit CHAR(1) NOT NULL,
content TEXT,
reply TEXT
)');
//新建内容 初始化网站设置内容
$web_name = 'abcBook PHP+SQLITE (ABC留言本 2013.04)';//网站名称
$web_pswd = md5('admin');//管理密码 md5加密 21232f297a57a5a743894a0e4a801fc3
$web_info = 'PHP+SQLITE简约版 体积小巧 简单实用 管理密码:admin';//网站公告
sqlite_query($db,"
INSERT INTO config(name,pswd,pv,audit,size,info)
VALUES('$web_name','$web_pswd',0,0,10,'$web_info')
");
header('location:?');
}
//自定义函数
function ok(){
exit('
<meta http-equiv="refresh" content="3; url=?">
<span style="color:red;">操作成功!</span>
<a href="?">点此返回</a> 3秒后自动跳转页面...
');
}
function html($value){
$value = htmlspecialchars($value,ENT_QUOTES);//转实体
if(get_magic_quotes_gpc()) $value = stripslashes($value);//反斜杠
return $value;
}
//读取数据库设置变量
$sql = sqlite_query($db,'SELECT * FROM config');
$rs = sqlite_fetch_array($sql);
$admin_pswd = $rs['pswd'];//管理密码 password
$web_name = $rs['name'];//网站名称
$web_size = $rs['size'];//每页显示
$web_info = $rs['info'];//网站公告
$web_info = str_replace(' ',' ',nl2br($web_info));//处理空格换行
$web_audit = $rs['audit'];//审核功能
$web_pv = $rs['pv']; //网站浏览量
sqlite_query($db,"UPDATE config SET pv = $web_pv + 1");//递增浏览量
$id = isset($_GET['id']) ? intval(trim($_GET['id'])) : '';
$cookie = isset($_COOKIE['cookie']) ? $_COOKIE['cookie'] : '';
$cookies = md5($admin_pswd);
//登录 生成COOKIE
if(isset($_POST['login'])){
if(md5($_POST['login']) == $admin_pswd){
setcookie('cookie',$cookies);
header('location:?');
}else{
header('refresh:3;url=?login');
exit('
<span style="color:red;">密码错误!</span>
<a href="?login">返回</a>
三秒后自动跳转页面...
');
}
}
//退出 清楚COOKIE
if(isset($_GET['exit'])){
setcookie('cookie','');
header('location:?');
}
echo <<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
body{width:750px;margin:10px auto;border:#eee 5px solid;overflow:auto;padding:8px;word-wrap:break-word;}
textarea{width:95%;height:80px;}
input,select{font-size:12px;}
body,textarea{font-size:14px;font-family:宋体,Arial;line-height:25px;color:#333;}
a{color:#168;text-decoration:none;}
hr{height:1px;border:none;border-bottom:1px dashed #abc;}
div{padding:15px;}
span{color:#e33;}
form{margin:0;}
</style>
<title>{$web_name}</title>
</head>
<body>
<a href="?" style="font-size: 18px;">{$web_name}</a><hr />
HTML;
//登陆界面
if(isset($_GET['login']) && !$cookie){
exit('
<form method="post">
管理密码:<input name="login" type="password"/>
<input type="submit" value=" 提 交 "/>
</form>
');
}
//登录后才能执行的操作
if($cookie == $cookies){
ini_set('max_execution_time','60');//设置页面超时时间秒
//删除
if(isset($_GET['delete'])){
$id = intval(trim($_GET['id']));//去除两边空格转成整数
sqlite_query($db,"DELETE FROM book WHERE id = $id");//删除
ok();
}
//回复 修改 审核
if(isset($_POST['id'])){
$id = intval(trim($_POST['id']));
$audit = $_POST['audit'] ? 1 : 0;
$reply = html($_POST['reply']);
$content = html($_POST['content']);
sqlite_query($db,"
UPDATE book SET
content = '$content',
reply = '$reply',
audit = $audit
WHERE id = $id
");
ok();
}
//修改配置
if(isset($_POST['name']) && $_POST['name']){
$pv = ($_POST['pv'] < 1) ? 1 : intval(trim($_POST['pv']));
$size = ($_POST['size'] > 1) ? intval(trim($_POST['size'])) : 10;
$pswd = $_POST['pswd'] ? md5($_POST['pswd']) : $admin_pswd;
$audit = $_POST['audit'] ? 1 : 0;
$name = html($_POST['name']);
$info = html($_POST['info']);
sqlite_query($db,"
UPDATE config SET
name = '$name',
pswd = '$pswd',
info = '$info',
audit = $audit,
size = $size,
pv = $pv
");
ok();
}
}
//修改 回复 审核 删除 界面
if(isset($_GET['reply']) && $cookie){
$sql = sqlite_query($db,"SELECT * FROM book WHERE id = $id");
$row = sqlite_fetch_array($sql);
$ip = $row['ip'];
$time = $row['time'];
$time = date('Y-m-d H:i:s',$time);
$audit = $row['audit'];
$reply = $row['reply'];
$content = $row['content'];
$yes = $audit ? 'checked="checked"' : '';
$no = $audit ? '' : 'checked="checked"';
echo <<<HTML
<a>管理 ID:{$id}</a> | TIME:{$time} | IP:{$ip}
<form method="post">
修改: <br/><textarea name="content">{$content}</textarea><br/>
回复: <br/><textarea name="reply">{$reply}</textarea><br/>
审核:
<input type="radio" name="audit" value="1" {$yes}/>已审
<input type="radio" name="audit" value="0" {$no} />未审
<input type="hidden" name="id" value="{$id}" />
<input type="hidden" name="time" value="{$time}" />
<input type="submit" value=" 提 交 "/>
<a href="?delete&id={$id}" onclick="return confirm('确定删除?');">删除</a>
</form>
HTML;
exit;
}
//管理界面
if($cookie){
$on = ($web_audit == 1) ? 'checked="checked"' : '';
$off = ($web_audit == 0) ? 'checked="checked"' : '';
echo <<<HTML
<span>修改网站设置</span>
<form method="post">
名称:
<input name="name" type="text" value="{$web_name}"/> 网站名称<br/>
显示:
<input name="size" type="text" value="{$web_size}"
onkeyup="this.value=this.value.replace(/\D/g,'')"
onafterpaste="this.value=this.value.replace(/\D/g,'')"
/> 每页显示多少条<br/>
浏览:
<input name="pv" type="text" value="{$web_pv}"
onkeyup="this.value=this.value.replace(/\D/g,'')"
onafterpaste="this.value=this.value.replace(/\D/g,'')"
/> 点击量<br/>
密码:
<input name="pswd" type="password"/> 管理密码 如不修改请留空<br/>
审核:
<input name="audit" type="radio" value="1" {$on}/