PHP+ACCESS 文章管理程序代码

代码如下:

<?php
session_start();
//==========================
//作者:biyuan
//时间:2006.07
//联系:QQ6010707
//==========================
?>
<html>
<head>
<title>碧原网络PHP+ACCESS文章管理系统</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<style type="text/css">
body {
margin:0px;
text-align:center;
font-size:12px;
font-family:verdana;
}
td {
font-size:12px;
height:28px;
padding:4px;
font-family:verdana;
}
A:link,
A:visited,
A:active {
color: #005a17; text-decoration: none;
}
A:hover {
color: #ff5a00; text-decoration: underline;
}
</style>
</head>
<body>
<?php
//==================================
//连接数据库
//==================================
@$conn = new com("ADODB.Connection");
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("article.mdb"));
//==================================
//文章导航
//==================================
function article_menu(){
global $conn;
@$sql = "Select * From List";
@$rs = $conn->Execute($sql);
while(!$rs->Eof){
echo "| <a href=\"?classid=" . $rs->Fields[2]->value . "\">" . $rs->Fields[1]->value . "</a> ";
$rs->MoveNext();
}
echo "| <a href=\"?admin=login\">后台管理</a>\r\n";
$rs->Close();
if(@$_SESSION["ARTICLEADMIN"] == "BY_PHP_ARTICLE"){
echo "<br />管理选项-> | <a href=\"?admin=class\">分类管理</a> | <a href=\"?admin=insert\">发表文章</a> | <a href=\"?admin=list\">文章列表</a> | <a href=\"?admin=logout\">退出登陆</a>";
}
}
//==================================
//文章列表:article_list(文章分类ID)
//==================================
function article_list($str){
global $conn;
@$sql = "Select id,by_title,by_name,by_time,by_count From Article Where by_class = " . $str . " Order By id desc";
@$rs = $conn->Execute($sql);
if(!$rs->Eof){
echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#cccccc\">\r\n"
. " <tr bgcolor=\"#F3F3F3\" align=\"center\">\r\n"
. " <td>文章标题</td><td>文章作者</td><td>发表时间</td><td>浏览次数</td>\r\n"
. " </tr>\r\n";
while(!$rs->Eof){
echo " <tr bgcolor=\"#FFFFFF\">\r\n"
. " <td><a href=\"?artid=" . $rs->Fields[0]->value . "\">" . $rs->Fields[1]->value . "</a></td><td>" . $rs->Fields[2]->value . "</td><td>" . date("Y-m-d H:i:s",$rs->Fields[3]->value) . "</td><td>" . $rs->Fields[4]->value . "</td>\r\n"
. " </tr>\r\n";
$rs->MoveNext();
}
echo "</table>\r\n";
}
else {
echo "<br />该分类不存在或暂时没有任何文章!";
}
$rs->Close();
}
//==================================
//文章详细:article_look(文章ID)
//==================================
function article_look($str){
global $conn;
@$sql = "Select * From Article Where id = " . $str;
@$rs = $conn->Execute($sql);
@$usql= "Update Article Set by_count = (by_count + 1) Where id = " . $str;
$conn->Execute($usql);
if(!$rs->Eof){
@$body = $rs->Fields[5]->value;
$body = str_replace("[url=file://%22,%22%22,$body/]\\","",$body[/url]);
echo "<table border=\"0\" width=\"60%\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#cccccc\">\r\n"
. " <tr bgcolor=\"#F3F3F3\" align=\"center\">\r\n"
. " <td style=\"font-size:14px;font-weight:bold\">" . $rs->Fields[1]->value . "</td>\r\n"
. " </tr>\r\n"
. " <tr bgcolor=\"#F3F3F3\" align=\"center\">\r\n"
. " <td>文章作者:" . $rs->Fields[2]->value . " | 发表时间:" . date("Y-m-d H:i:s",$rs->Fields[3]->value) . " | 浏览次数:" . $rs->Fields[4]->value . "</td>\r\n"
. " </tr>\r\n"
. " <tr bgcolor=\"#FFFFFF\">\r\n"
. " <td>" . $body . "</td>\r\n"
. " </tr>\r\n"
. " <tr bgcolor=\"#F3F3F3\">\r\n"
. " <td align=\"right\">【 <a href=\"javascript:history.back();\">返 回</a> 】  【 <a href=\"javascript:print();\">打 印</a> 】  【 <a href=\"javascript:close();\">关 闭</a> 】</td>\r\n"
. " </tr>\r\n"
. " </table>\r\n"
. " <script language=\"JavaScript\">document.title += \"--" . $rs->Fields[1]->value . "\";</script>\r\n";
}
else {
echo "<br />该文章不存在或已被管理员删除!";
}
$rs->Close();
}
//==================================
//后台:分类管理
//==================================
function admin_class(){
global $conn;
@$sql = "Select * From List";
@$rs = $conn->Execute($sql);
echo "<form action=\"\" method=\"post\" name=\"frm\">\r\n";
while(!$rs->Eof){
echo "类别:<input type=\"text\" value=\"" . $rs->Fields[1]->value . "\" name=\"class_" . $rs->Fields[0]->value . "\" /> 编号:<input type=\"text\" value=\"" . $rs->Fields[2]->value . "\" name=\"class_cid_" . $rs->Fields[0]->value . "\" /> <input type=\"button\" value=\"修改\" onclick=\"frm.action='?admin=class&class=edit&id=" . $rs->Fields[0]->value . "';submit();\" /> <input type=\"button\" value=\"删除\" onclick=\"frm.action='?admin=class&class=del&id=" . $rs->Fields[0]->value . "';submit();\" /><br />\r\n";
$rs->MoveNext();
}
echo "类别:<input type=\"text\" name=\"class_name\" /> 编号:<input type=\"text\" name=\"class_cid\" /> <input type=\"button\" value=\"增加\" onclick=\"frm.action='?admin=class&class=add';submit();\" /> <input type=\"button\" value=\"闲置\" disabled />\r\n"
. "</form>\r\n";
//增加一个类别
if(@$_GET["class"] == "add"){
if(@$_POST["class_name"] == "" || @$_POST["class_cid"] == ""){
echo "<br />填写不完整!";
echo "<script language=\"JavaScript\">setTimeout(\"history.back();\", 2000);</script>";
exit();
}
else {
@$sql = "Insert into List(by_list,by_cid) Values('" . $_POST["class_name"] . "' , '" . $_POST["class_cid"] . "')";
$conn->Execute($sql);
echo "<br />添加成功!";
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=class';\", 2000);</script>";
}
}
//修改一个类别
if(@$_GET["class"] == "edit"){
if(@$_POST["class_" . $_GET["id"]] == "" || @$_POST["class_cid_" . $_GET["id"]] == ""){
echo "<br />填写不完整!";
echo "<script language=\"JavaScript\">setTimeout(\"history.back();\", 2000);</script>";
exit();
}
else {
@$sql = "Update List Set by_list = '" . $_POST["class_" . $_GET["id"]] . "' , by_cid = '" . $_POST["class_cid_" . $_GET["id"]] . "' Where id = " . $_GET["id"];
$conn->Execute($sql);
echo "<br />修改成功!";
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=class';\", 2000);</script>";
}
}
//删除一个类别
if(@$_GET["class"] == "del"){
@$sql = "Delete From List Where id = " . $_GET["id"];
$conn->Execute($sql);
echo "<br />删除成功!";
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=class';\", 100);</script>";
}
}
//==================================
//后台:发表文章(支持HTML)
//==================================
function admin_insert(){
global $conn;
if(@$_GET["innert"] == "add"){
if(@$_POST["title"] == "" || @$_POST["name"] == "" || @$_POST["class"] == "" || @$_POST["body"] == ""){
echo "<br />填写不完整!";
echo "<script language=\"JavaScript\">setTimeout(\"history.back();\", 2000);</script>";
exit();
}
else {
@$body = $_POST["body"];
$body = str_replace("'", "''", $body);
$body = str_replace("\r\n", "<br />", $body);
@$sql = "Insert into article(by_title,by_name,by_time,by_count,by_body,by_class) Values('" . $_POST["title"] . "' , '" . $_POST["name"] . "' , #" . date("Y-m-d G:i:s") . "# , 0 , '" . $body . "' , '" . $_POST["class"] . "')";
$conn->Execute($sql);
echo "<br />添加成功!";
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=insert';\", 2000);</script>";
}
}
else {
echo "<div style=\"width:590px;text-align:left\">\r\n"
. "<form action=\"?admin=insert&innert=add\" method=\"post\">\r\n"
. "文章标题:<input type=\"text\" name=\"title\" /><br />\r\n"
. "文章作者:<input type=\"text\" name=\"name\" /><br />\r\n"
. "文章类别:<select name=\"class\">\r\n";
@$sql = "Select * From List";
@$rs = $conn->Execute($sql);
while(!$rs->Eof){
echo "<option value=\"" . $rs->Fields[2]->value . "\">" . $rs->Fields[1]->value . "</option>\r\n";
$rs->MoveNext();
}
echo "</select><br />\r\n"
. "文章正文:<textarea cols=\"70\" rows=\"14\" name=\"body\"></textarea><br />\r\n"
. "<center><input type=\"submit\" value=\"提交\" /> <input type=\"reset\" value=\"重置\" /></center>\r\n"
. "</form>\r\n"
. "</div>\r\n";
}
}
//==================================
//后台:文章列表
//==================================
function admin_list(){
global $conn;
@$sql = "Select id,by_title,by_name,by_time,by_count,by_class From Article Order By id desc";
@$rs = $conn->Execute($sql);
if(!$rs->Eof){
echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#cccccc\">\r\n"
. " <tr bgcolor=\"#F3F3F3\" align=\"center\">\r\n"
. " <td>文章标题</td><td>文章分类<td>文章作者</td><td>发表时间</td><td>浏览次数</td><td>操作</td>\r\n"
. " </tr>\r\n";
while(!$rs->Eof){
@$sql = "Select * From List Where by_cid = " . $rs->Fields[5]->value;
@$crs = $conn->Execute($sql);
@$cid = $crs->Fields[1]->value;
echo " <tr bgcolor=\"#FFFFFF\">\r\n"
. " <td><a href=\"?artid=" . $rs->Fields[0]->value . "\">" . $rs->Fields[1]->value . "</a></td><td>" . $cid . "</td><td>" . $rs->Fields[2]->value . "</td><td>" . $rs->Fields[3]->value . "</td><td>" . $rs->Fields[4]->value . "</td><td><a href=\"?admin=list&list=edit&id=" . $rs->Fields[0]->value . "\">编辑</a> | <a href=\"?admin=list&list=del&id=" . $rs->Fields[0]->value . "\">删除</a></td>\r\n"
. " </tr>\r\n";
$crs->Close();
$rs->MoveNext();
}
echo "</table>\r\n";
}
else {
echo "<br />该分类不存在或暂时没有任何文章!";
}
$rs->Close();
//修改文章
if(@$_GET["list"] == "edit"){
if(@$_GET["edit"] == "true"){
if(@$_POST["title"] == "" || @$_POST["name"] == "" || @$_POST["class"] == "" || @$_POST["body"] == ""){
echo "<br />填写不完整!";
echo "<script language=\"JavaScript\">setTimeout(\"history.back();\", 2000);</script>";
exit();
}
else {
@$body = $_POST["body"];
$body = str_replace("'", "''", $body);
$body = str_replace("\r\n", "<br />", $body);
@$sql = "Update article Set by_title = '" . $_POST["title"] . "' , by_name = '" . $_POST["name"] . "' , by_count = " . $_POST["count"] . " , by_body = '" . $body . "' , by_class = '" . $_POST["class"] . "' Where id = " . $_GET["id"];
$conn->Execute($sql);
echo "<br />修改成功!";
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=list';\", 2000);</script>";
}
}
else {
@$sql = "Select * From Article Where id = " . $_GET["id"];
@$rs = $conn->Execute($sql);
echo "<div style=\"width:590px;text-align:left\">\r\n"
. "<form action=\"?admin=list&list=edit&edit=true&id=" . $rs->fields[0]->value . "\" method=\"post\">\r\n"
. "文章标题:<input type=\"text\" name=\"title\" value=\"" . $rs->fields[1]->value . "\" /><br />\r\n"
. "文章作者:<input type=\"text\" name=\"name\" value=\"" . $rs->fields[2]->value . "\" /><br />\r\n"
. "浏览次数:<input type=\"text\" name=\"count\" value=\"" . $rs->fields[4]->value . "\" /><br />\r\n"
. "文章类别:<select name=\"class\" id=\"class\">\r\n";
@$sql = "Select * From List";
@$crs = $conn->Execute($sql);
while(!$crs->Eof){
echo "<option value=\"" . $crs->Fields[2]->value . "\">" . $crs->Fields[1]->value . "</option>\r\n";
$crs->MoveNext();
}
$crs->close();
@$body = $rs->Fields[5]->value;
$body = str_replace("<br />","\r\n",$body);
echo "</select><br />\r\n"
. "<script language=\"JavaScript\">\r\n"
. "document.getElementById(\"class\").selectedIndex = " . $rs->fields[6]->value . " - 1;\r\n"
. "</script>\r\n"
. "文章正文:<textarea cols=\"70\" rows=\"14\" name=\"body\">" . $body . "</textarea><br />\r\n"
. "<center><input type=\"submit\" value=\"提交\" /> <input type=\"reset\" value=\"重置\" /></center>\r\n"
. "</form>\r\n"
. "</div>\r\n";
}
}
//删除文章
if(@$_GET["list"] == "del"){
@$sql = "Delete From Article Where id = " . $_GET["id"];
$conn->Execute($sql);
echo "<br />删除成功!";
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=list';\", 100);</script>";
}
}
//==================================
//权限验证
//==================================
function admin_session(){
if(@$_SESSION["ARTICLEADMIN"] != "BY_PHP_ARTICLE"){
echo "<br />请先登陆!";
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=login';\", 2000);</script>";
exit();
}
}
//==================================
//后台登陆
//==================================
function admin_login(){
if(@$_SESSION["ARTICLEADMIN"] == "BY_PHP_ARTICLE"){
echo "<script language=\"JavaScript\">window.location.href='?admin=admin';</script>";
}
else{
echo "<table border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#cccccc\">\r\n"
. " <tr bgcolor=\"#F3F3F3\" align=\"center\">\r\n"
. " <td><strong>管理员登陆</strong></td>\r\n"
. " </tr>\r\n"
. " <tr bgcolor=\"#FFFFFF\">\r\n"
. " <form method=\"post\" action=\"?admin=check\">\r\n"
. " <td><input type=\"password\" name=\"adminPass\" /><input type=\"submit\" value=\"确定\" /></td>\r\n"
. " </form>\r\n"
. " </tr>\r\n"
. "</table>\r\n";
}
}
//==================================
//登陆验证
//==================================
function admin_check(){
if(trim($_POST["adminPass"]) != "admin"){
echo "<br />错误的密码!";
echo "<script language=\"JavaScript\">setTimeout(\"history.back();\", 2000);</script>";
}
else {
echo "<br />登陆成功!";
@$_SESSION["ARTICLEADMIN"] = "BY_PHP_ARTICLE";
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=admin';\", 2000);</script>";
}
}
//==================================
//URL参数列表
//==================================
function page_load(){
@$classid = $_GET["classid"];
if($classid != ""){
if(!is_numeric($classid)){
echo "<br />错误的参数!";
return false;
}
else {
article_list($classid);
}
}
@$artid = $_GET["artid"];
if($artid != ""){
if(!is_numeric($artid)){
echo "<br />错误的参数!";
return false;
}
else {
article_look($artid);
}
}
@$admin = $_GET["admin"];
if($admin == "login"){
admin_login();
}
if($admin == "check"){
admin_check();
}
if($admin == "admin"){
admin_session();
echo "<br />登陆成功!请选择功能菜单进行操作.";
}
if($admin == "logout"){
session_destroy();
echo "<br />已成功退出!";
echo "<script language=\"JavaScript\">setTimeout(\"window.location.href='?admin=login';\", 2000);</script>";
}
if($admin == "class"){
admin_session();
admin_class();
}
if($admin == "insert"){
admin_session();
admin_insert();
}
if($admin == "list"){
admin_session();
admin_list();
}
if($classid == "" && $artid == "" && $admin == ""){
echo "<script language=\"JavaScript\">window.location.href='?classid=1';</script>";
}
}
?>
<div style="width:100%;text-align:left;background:#cccccc;line-height:20px;">
<br /><br /><br />文章分类-> <?=article_menu();?>
</div>
<?=page_load();?>
<?php
$conn->Close();
?>
</body>
</html>

(0)

相关推荐

  • 三种php连接access数据库方法

    一种是利用php的pdo,一种是odbc,com接口来与access数据库连接. 利用pdo与access数据库连接  复制代码 代码如下: $path ="f:fontwww.jb51.netspiderresult.mdb";  $conn = new pdo("sqlite:$path"); if( $conn ) {  echo ('connection pdo success'); } else {  echo ('cnnection pdo fail ,

  • PHP 的ArrayAccess接口 像数组一样来访问你的PHP对象

    复制代码 代码如下: interface ArrayAccess boolean offsetExists($index) mixed offsetGet($index) void offsetSet($index, $newvalue) void offsetUnset($index) 下面的例子展示了如何使用这个接口,例子并不是完整的,但是足够看懂,:-> 复制代码 代码如下: <?php class UserToSocialSecurity implements ArrayAccess

  • PHP读取ACCESS数据到MYSQL的代码

    复制代码 代码如下: <?php header('ontent-Type:text/html;charset=GB2312');//避免输出乱码 $dbhost ="localhost"; $dbuser ="root"; $dbpassword = "123456"; $dbname = "139miaosha"; mysql_connect($dbhost,$dbuser,$dbpassword) or die(&q

  • PHP连接Access数据库的方法小结

    PHP代码: 需要注意php获取路径用的是realpath 复制代码 代码如下: <?php $connstr="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("data.mdb"); $connid=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC); $issuetime=date("Y-m-d

  • php连接Access数据库错误及解决方法

    php+access连接数据库常用的方式一般有两种. 推荐的代码 需要注意php获取路径用的是realpath 复制代码 代码如下: <?php $connstr="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("data.mdb"); $connid=odbc_connect($connstr,"","",SQL_CUR_USE_ODBC); $i

  • php静态化页面 htaccess写法详解(htaccess怎么写?)

    1 . 如何让自己的本地APACHE服务器支持.htaccess 如何让自己的本地APACHE服务器支持".htaccess"呢?其实只要简单修改一下apache的httpd.conf设置就可以让APACHE支持.htaccess了,来看看操作 打开httpd.conf文件(在那里? APACHE目录的CONF目录里面),用文本编辑器打开后,查找 (1) Options FollowSymLinks AllowOverride None 改为 Options FollowSymLink

  • PHP+ACCESS 文章管理程序代码

    复制代码 代码如下: <?php session_start(); //========================== //作者:biyuan //时间:2006.07 //联系:QQ6010707 //========================== ?> <html> <head> <title>碧原网络PHP+ACCESS文章管理系统</title> <meta http-equiv="content-type&q

  • JS实现带鼠标效果的头像及文章列表代码

    本文实例讲述了JS实现带鼠标效果的头像及文章列表代码.分享给大家供大家参考.具体如下: 这是一种带图片功能的文章或新闻列表功能,鼠标滑过标题列表显示说明和图片,多见于SNS交友网站,不过你喜欢的话,你完全可以用哦. 运行效果截图如下: 在线演示地址如下: http://demo.jb51.net/js/2015/js-mouse-style-face-article-list-demo/ 具体代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.

  • Python登录并获取CSDN博客所有文章列表代码实例

    分析登录过程 这几天研究百度登录和贴吧签到,这百度果然是互联网巨头,一个登录过程都弄得复杂无比,简直有毒.我研究了好几天仍然没搞明白.所以还是先挑一个软柿子捏捏,就选择CSDN了. 过程很简单,我也不截图了.直接打开浏览器,然后打开Fiddler,然后登录CSDN.然后Fiddler显示浏览器向https://passport.csdn.net/account/login?ref=toolbar发送了一个POST请求,这个请求包含了登录表单,而且还是未加密的.当然CSDN本身还是使用了HTTPS

  • Asp.net在线备份、压缩和修复Access数据库示例代码

    1.问题的提出 在设计中小型Web应用程序时,可以选择Microsoft Accesss为数据库.在数据库的使用过程中经常性进行增加和删除操作.事实上,Microsoft Access并不能有效地释放已分配的但被删除的对象空间,这将意味着即使你删除了一个对象,而这个对象仍然占据着数据库的空间,使得数据库越来越大.不但占用不必要的空间,而且降低了数据库的效率.特别在虚拟站点上的问题尤为突出.因此对Access数据库进行压缩瘦身很有实际意义. 虽然Access数据库自身具有"压缩和修复数据库&quo

  • PHP 文本文章分页代码 按标记或长度(不涉及数据库)

    实例代码: 复制代码 代码如下: <?php /** * ********************************************************** * Read Me * 文章分页 * * 分页方式,可以按字数分页,按换行分页,按特殊标记分页等 * 其实实现思路是一样的,只是将其按一定规律放入一个数组 * 然后根据 url 传入的参数取得某个片段即可 * 大家完全可以写一个功能强大的函数保存起来以备不时之需 * * 题外话:很多编辑器都有插入分页按钮,利用插入的代码可

  • Linq to XML 用一句话读出RSS文章列表代码

    在页面的 Page_Load() 方法中写上这句话就行了: 复制代码 代码如下: new XDocument( new XElement("ol", from item in XDocument.Load("http://cnblogs.com/rss").Descendants("item") select new XElement[]{ new XElement("li", new XElement("a&quo

  • 引用文章链接代码复制自动加链接功能

    function copyToClipBoard(){ var clipBoardContent=""; clipBoardContent+=document.title; clipBoardContent+=""; clipBoardContent+=this.location.href; window.clipboardData.setData("Text",clipBoardContent); alert("复制成功,请粘贴到您的

  • js对文章内容进行分页示例代码

    Thinkphp中文章显示代码: 复制代码 代码如下: <div id="showContent">{$article.content|htmlspecialchars_decode}</div> <div id="articlePages"></div> js实现代码: 复制代码 代码如下: <script type="text/javascript"> var obj = docum

  • 编写可维护面向对象的JavaScript代码[翻译]

    Writing maintainable Object-Oriented (OO) JavaScript will save you money and make you popular. Don't believe me? Odds are that either you or someone else will come back and work with your code. Making that as painless an experience as possible will s

  • SQL 随机查询 包括(sqlserver,mysql,access等)

    SQL Server: Sql代码 复制代码 代码如下: Select TOP N * From TABLE Order By NewID() NewID()函数将创建一个 uniqueidentifier 类型的唯一值.上面的语句实现效果是从Table中随机读取N条记录. Access: Sql代码 复制代码 代码如下: Select TOP N * From TABLE Order By Rnd(ID) Rnd(ID) 其中的ID是自动编号字段,可以利用其他任何数值来完成,比如用姓名字段(U

随机推荐