首页 编程教程正文

PHP+MYSQL的文章管理系统(一)

piaodoo 编程教程 2020-02-02 13:46:32 1003 0 php教程

###############################################  
此篇文章属原创,如有引用,请标明作者信息。  
Email: leo_cdp@yeah.net
http://www.cfeng.net/
本文代码任意转载,使用请保留此声明
###############################################  
去年写了个文本管理总觉得有些不爽再加上申请了主机所以写个PHP+MYSQL的对文章进行管理测试期间
受到广大网友的支持现将代码公布
功能说明:
文章的基本操作:添加,修改,锁定,解锁,推荐,删除等待
并有强大功能的搜索,评论,推荐给朋友等功能,并对安全性进行着重加强,漂亮的界面人性化的设计。
主要文件列表:
setup.php    安装程序,运行后即可使用本系统!
index.php    显示
manager.php  添加,管理文章。
change.php   对已存在文章的操作。
edit_article.php 文章修改
commend.php  推荐文章给朋友。
read_article.php 文章阅读。
ping.php     发表文章评论。
search.php   文章搜索
type_manager.php  类型管理
login.php    管理员登陆。
config.php   主要配置文件
func.php     函数文件
footer.inc,header.inc,nav.inc包含文件。
list.txt     类型列表
以及其它一些周边程序
管理系统演示地址:
http://www.cfeng.net/article/
########################config.php 主要配置文件##########################
<?
$host="localhost";                   #数据库主机
$database_usn="cfeng.net";           ##数据库用户
$database_pwd="cfeng.net";           ##数据库密码
$database="cfeng.net";               ##数据库
$table="cfeng.net";                  ##要存放文章的表
$ping_tab="ping_tab1";               ##存放评论的表
$admin_usn="leo";                    ##管理员用户名
$admin_pwd="leo";                    ##管理员密码
$admin_mail="leo_cdp@yeah.net";      ##管理员信箱
$pagenum="20";                       ##每页显示文章数
$sess=md5($admin_usn.$admin_pwd);    ##登陆认证采用MD5生成
?>
#####################func.php  函数文件 ###################################
<?
require "./inc/config.php";
function mscon()##数据库链接
{   
  global $host,$database_usn,$database_pwd;
  @mysql_connect("$host","$database_usn","$database_pwd") or die("对不起,数据库连接错误!请稍候再来,或与管理员联系");
}
function check_login()
{  global $sess;
if(!session_is_registered("sess_0230a09a07cab1df8112d00b1f9a9719"))
   {
    if($sess_0230a09a07cab1df8112d00b1f9a9719!=$sess)
       {
         redir("login.php");
         exit;
       }
   }
}
function redir($addr)
  {
    header("location:$addr");
   }
function add_article()##本系统实行宽进严出所以添加文章部份显得略为简单!
{
   global $database,$table,$title,$cont,$type,$html;
   $dat=date(Y年m月d日);
   $title=htmlspecialchars($title);
   $query="insert into $table(title,cont,type,time,html) values('$title','$cont','$type','$dat','$html')";
   $res=mysql_db_query("$database",$query);
   if(!$res)
   echo mysql_error();
}
function add_hits($id)##添加浏览次数!
{
global $database,$table;
$query="update $table set hits=hits+1 where id=$id";
   $res=mysql_db_query("$database",$query);
}
function add_comm($id)##把本文加为推荐文章
{
global $database,$table;
$query="update $table set comm=1 where id=$id";
   $res=mysql_db_query("$database",$query);
}
function un_comm($id)##清除推荐!
{
global $database,$table;
$query="update $table set comm='0' where id=$id";
   $res=mysql_db_query("$database",$query);
}
function add_lock($id)##锁定文章
{
global $database,$table;
$query="update $table set locked='1' where id=$id";
   $res=mysql_db_query("$database",$query);
}

function un_lock($id)##清除锁定!
{
global $database,$table;
$query="update $table set locked=0 where id=$id";
   $res=mysql_db_query("$database",$query);
}
function add_p_num($id)##添加评论次数!
{
global $database,$table;
$query="update $table set p_num=p_num+1 where id=$id";
   $res=mysql_db_query("$database",$query);
}
function add_del($id)##删除文章!
{
global $database,$table;
$query="delete from $table where id='$id'";
   $res=mysql_db_query("$database",$query);
}
########################setup.php 安装文件######################
<?  
session_start();
require"./inc/func.php";
check_login();
?>
<?
if($sub)
{
   $file_cont="<?\n #don't edit thisfile use the setup.php\n";
   $file_cont.="\$host=\"$host\";#your database server address\n";
   $file_cont.="\$database_usn=\"$database_usn\";\n";
   $file_cont.="\$database_pwd=\"$database_pwd\";\n";
   $file_cont.="\$database=\"$database\";\n";
   $file_cont.="\$table=\"$table\";\n";
   $file_cont.="\$ping_tab=\"$ping_tab\";\n";
   $file_cont.="\$admin_usn=\"$admin_usn\";\n";
   $file_cont.="\$admin_pwd=\"$admin_pwd\";\n";
   $file_cont.="\$admin_mail=\"$admin_mail\";\n";
   $file_cont.="\$pagenum=\"$pagenum\";\n";
   $file_cont.="\$sess=md5(\$admin_usn.\$admin_pwd);\n";
   $file_cont.="\n";
   $file_cont.="?>";
   $fp=fopen("./inc/config.php","w");
   if(fputs($fp,$file_cont))
      echo "配置完成正检测各选项的正确性<BR>";
   else echo "文件写入错误,请检测文件所在目录的权限<br>";
   fclose($fp);
      echo "正在检测数据连接.........." ;
   if(@mysql_connect("$host","$database_usn","$database_pwd"))
      {
        echo  "成功!<BR>" ;
        $query="CREATE TABLE $table(
                     id int(4) NOT NULL auto_increment,
                     title varchar(55) NOT NULL,
                     cont text NOT NULL,
                     time varchar(14) NOT NULL,
                     type varchar(20) NOT NULL,
                     comm int(1) DEFAULT '0' NOT NULL,
                     p_num int(2) DEFAULT '0' NOT NULL,
                     locked int(1) DEFAULT '0' NOT NULL,
                     hits int(4) DEFAULT '0' NOT NULL,
                     html int(1) DEFAULT '1' NOT NULL,
                     PRIMARY KEY (id),
                     UNIQUE id (id),
                     KEY id_2 (id)
                     ) " ;
        if(mysql_db_query($database,$query))
          echo"数据库 $table 建立成功<BR>".mysql_error();
        else
          echo"数据库 $table 建立失败<BR>";
        $query="CREATE TABLE $ping_tab (
                      id int(4) NOT NULL auto_increment,
                      p_id int(4) DEFAULT '0' NOT NULL,
                      name varchar(50) NOT NULL,
                      mail varchar(200) NOT NULL,
                      p_cont text NOT NULL,
                      time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
                      ip varchar(15) NOT NULL,
                      PRIMARY KEY (id),
                      UNIQUE id (id),
                      KEY id_2 (id)
                      )";
        if(mysql_db_query($database,$query))
          {
            echo"用户评论数据库 $ping_tab 建立成功<BR>恭喜,文章管理系统安装成功!请<a href=login.php>这边走</a>进行基本设置!<BR>";
            $fp=fopen("setup.php","r");
            $file_cont=fread($fp,filesize("setup.php"));
            $file_cont="<? \nsession_start();\nrequire\"./inc/func.php\";\n check_login();\n?>\n".$file_cont;
            $fp=fopen("setup.php","w");
            fputs($fp,$file_cont);
            fclose($fp);
          }
        else
          echo"用户评论数据库$ping_tab建立失败<BR>";
    }
   else
      echo "数据库连接失败!请检测你用户名密码的正确性!<BR>";
  exit();
  }
require "./inc/header.inc";
?>
<script language="javascript">
function db_pwd()
{
  var theResult = true;
  var elem4 = null;

  if (document.forms[0].elements[2].value == "" || document.forms[0].elements[2].value!=document.forms[0].elements[3].value)
  {
    alert("您两次输入的数据库密码不一致,或者为空!");
    document.forms[0].elements[2].value="";
    document.forms[0].elements[3].value="";
    theResult = false;

     }
  return theResult;
}
function admin_pwd()
{
  var theResult = true;
  var elem4 = null;
if (document.forms[0].elements[8].value == "" || document.forms[0].elements[8].value!=document.forms[0].elements[9].value)
  {
    alert("您两次输入的管理员密码不一致,或者为空!");
    document.forms[0].elements[8].value="";
    document.forms[0].elements[9].value="";
    theResult = false;

     }
  return theResult;
}
function go()
{
var theResult=true;
theResult =db_pwd()&&admin_pwd();
return theResult;
}
</script>
</head>
<body bgcolor="#FFFFFF">
<? require "./inc/nav.inc";?>
<form name="form1" method="post" action="<? echo $PHP_SELF; ?>" onsubmit="return go()";>
  <table border="0" cellspacing="0" cellpadding="0" align="center" style=text-align:left;>
    <tr>
      <td colspan="3">
        <div align="center">蓝狐文章管理安装程序<br>
          (请正确填写以下内容否则程序将无法使用)</div>
      </td>
    </tr>
    <tr>
      <td>数据库服务器:</td>
      <td colspan="2">
        <input type="text" name="host" value="localhost" class="border" size="30">
      </td>
    </tr>
    <tr>
      <td>数据库用户名: </td>
      <td colspan="2">
        <input type="text" name="database_usn" class="border" size="30">
      </td>
    </tr>
    <tr>
      <td>数据库用户密码:</td>
      <td colspan="2">
        <input type="password" name="database_pwd" class="border" size="30">
      </td>
    </tr>
    <tr>
      <td>数据库密码确认:</td>
      <td colspan="2">
        <input type="password" name="database_pwd2" class="border" size="30">
      </td>
    </tr>
    <tr>
      <td>数据库名:</td>
      <td colspan="2">
        <input type="text" name="database" class="border" size="30">
      </td>
    </tr>
    <tr>
      <td>存放文章的表:</td>
      <td colspan="2">
        <input type="text" name="table" class="border" size="30">
      </td>
    </tr>
    <tr>
      <td>存放评论的表:</td>
      <td colspan="2">
        <input type="text" name="ping_tab" class="border" size="30">
      </td>
    </tr>
    <tr>
      <td>管理员用户名:</td>
      <td colspan="2">
        <input type="text" name="admin_usn" class="border" size="30">
      </td>
    </tr>
    <tr>
      <td>管理员密码:</td>
      <td colspan="2">
        <input type="password" name="admin_pwd" class="border" size="30">
      </td>
    </tr>
    <tr>
      <td>管理员密码确认:</td>
      <td colspan="2">
        <input type="password" name="admin_pwd2" class="border" size="30">
      </td>
    </tr>
    <tr>
      <td>管理员邮件地址:</td>
      <td colspan="2">
        <input type="text" name="admin_mail" class="border" size="30">
      </td>
    </tr>
    <tr>
      <td>每页显示文章数:</td>
      <td colspan="2">
        <input type="text" name="pagenum" class="border" size="30">
      </td>
    </tr>
    <tr>
      <td>
        <div align="center"><br>
        </div>
      </td>
      <td>
        <div align="left"><br>
          <input type="submit" name="sub" value="submit" class="border">
            
          <input type="reset" name="reset" value="reset" class="border">
        </div>
      </td>
    </tr>
  </table>
  <p>  </p>
  </form>
<?require "./inc/footer.inc";?> 

版权声明:

本站所有资源均为站长或网友整理自互联网或站长购买自互联网,站长无法分辨资源版权出自何处,所以不承担任何版权以及其他问题带来的法律责任,如有侵权或者其他问题请联系站长删除!站长QQ754403226 谢谢。

有关影视版权:本站只供百度云网盘资源,版权均属于影片公司所有,请在下载后24小时删除,切勿用于商业用途。本站所有资源信息均从互联网搜索而来,本站不对显示的内容承担责任,如您认为本站页面信息侵犯了您的权益,请附上版权证明邮件告知【754403226@qq.com】,在收到邮件后72小时内删除。本文链接:http://www.piaodoo.com/3331.html

评论

搜索