Article Management System of PHP + MySQL (1)

Source: Internet
Author: User

######################################## #######
This article Article Original. If there is any reference, please indicate the author information.
Email: leo_cdp@yeah.net
Http://www.cfeng.net/
This article Code This statement is reprinted as needed.
######################################## #######
Last year, I wrote a text management document. I always felt a little uncomfortable. When I applied for a host, I wrote a PHP + MySQL document for management testing.
Supported by a large number of netizens, the Code is now published
Function Description:
Basic operations of the article: add, modify, lock, unlock, recommend, delete wait
It also provides powerful functions such as search, comment, and recommendation to friends. It also focuses on enhanced security and a user-friendly design of beautiful interfaces.
Main file list:
Setup. PHP installation Program , You can use this system after running!
Index. php display
Manager. php add and manage articles.
Change. php operations on existing articles.
Edit_article.php Article Modification
Commend. php recommends articles to friends.
Read read_article.php.
Ping. php post comments.
Search. php Article Search
Type_manager.php type management
Log On As the login. php administrator.
Config. php main configuration file
Func. php function File
Footer. Inc, header. Inc, Nav. inc contains files.
List.txt type list
And other peripheral programs
Management System demo address:
Http://www.cfeng.net/article/
######################## Config. main PHP configuration files ##########################
<?
$ Host = "localhost"; # Database Host
$ Database_usn = "cfeng.net"; # Database User
$ Database_pwd = "cfeng.net"; # Database Password
$ Database = "cfeng.net"; # Database
$ Table = "cfeng.net"; # table for storing articles
$ Ping_tab = "ping_tab1"; # comment table
$ Admin_usn = "Leo"; # administrator username
$ Admin_pwd = "Leo"; # administrator password
$ Admin_mail = "leo_cdp@yeah.net"; # administrator mailbox
$ Pagenum = "20"; # Number of articles displayed on each page
$ Sess = MD5 ($ admin_usn. $ admin_pwd); # use MD5 to generate login authentication
?>
##################### Func. PHP function file ###################################
<?
Require "./INC/config. php ";
Function mscon () # Database Link
{
Global $ host, $ database_usn, $ database_pwd;
@ Mysql_connect ("$ host", "$ database_usn", "$ database_pwd") or die ("sorry, database connection error! Please come back later or contact the Administrator ");
}
Function check_login ()
{Global $ sess;
If (! Session_is_registered ("sess_0230a09a07cab1df8da-d00b1f9a9719 "))
{
If ($ sess_0230a09a07cab1df8127d00b1f9a9719! = $ Sess)
{
Redir ("login. php ");
Exit;
}
}
}
Function redir ($ ADDR)
{
Header ("Location: $ ADDR ");
}
Function add_article () # This system implements wide-forward and strict-out, so it is a little simpler to add the 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) # Add browsing times!
{
Global $ database, $ table;
$ Query = "Update $ table set hits = hits + 1 where id = $ id ";
$ Res = mysql_db_query ("$ Database", $ query );
}
Function add_comm ($ id) # Add this article as a recommendation article
{
Global $ database, $ table;
$ Query = "Update $ table set comm = 1 where id = $ id ";
$ Res = mysql_db_query ("$ Database", $ query );
}
Function un_comm ($ id) # clear recommendation!
{
Global $ database, $ table;
$ Query = "Update $ table set comm = '0' where id = $ id ";
$ Res = mysql_db_query ("$ Database", $ query );
}
Function add_lock ($ id) # lock an article
{
Global $ database, $ table;
$ Query = "Update $ table set locked = '1' where id = $ id ";
$ Res = mysql_db_query ("$ Database", $ query );
}

Function un_lock ($ id) # clear lock!
{
Global $ database, $ table;
$ Query = "Update $ table set locked = 0 where id = $ id ";
$ Res = mysql_db_query ("$ Database", $ query );
}
Function add_p_num ($ id) # number of comments added!
{
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) # delete an article!
{
Global $ database, $ table;
$ Query = "delete from $ table where id = '$ id '";
$ Res = mysql_db_query ("$ Database", $ query );
}
######################## Setup. PHP installation file ######################
<?
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 "the configuration is complete and the correctness of each option is checked <br> ";
Else echo "file writing error. Check the permission of the directory where the file is located <br> ";
Fclose ($ FP );
Echo "detecting data connection ..........";
If (@ mysql_connect ("$ host", "$ database_usn", "$ database_pwd "))
{
Echo "successful! <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 "database $ table created successfully <br>". mysql_error ();
Else
Echo "database $ table creation failed <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 '2014-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 "User comment database $ ping_tab created successfully <br> congratulations, article management system installed successfully! <A href = login. php> go here </a> to perform basic settings! <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 "User comment database $ ping_tab creation failed <br> ";
}
Else
Echo "database connection failed! Check whether your username and password are correct! <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 ("the Database Password you entered twice is inconsistent, or it is blank! ");
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 ("the administrator password you entered twice is inconsistent, or it is blank! ");
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"> Blue Fox Article management installer <br>
(Please enter the following content correctly or the program will not be available) </div>
</TD>
</Tr>
<Tr>
<TD> database server: </TD>
<TD colspan = "2">
<Input type = "text" name = "host" value = "localhost" class = "border" size = "30">
</TD>
</Tr>
<Tr>
<TD> database username: </TD>
<TD colspan = "2">
<Input type = "text" name = "database_usn" class = "border" size = "30">
</TD>
</Tr>
<Tr>
<TD> Database User Password: </TD>
<TD colspan = "2">
<Input type = "password" name = "database_pwd" class = "border" size = "30">
</TD>
</Tr>
<Tr>
<TD> confirm the Database Password: </TD>
<TD colspan = "2">
<Input type = "password" name = "database_pwd2" class = "border" size = "30">
</TD>
</Tr>
<Tr>
<TD> Database Name: </TD>
<TD colspan = "2">
<Input type = "text" name = "Database" class = "border" size = "30">
</TD>
</Tr>
<Tr>
<TD> table for storing articles: </TD>
<TD colspan = "2">
<Input type = "text" name = "table" class = "border" size = "30">
</TD>
</Tr>
<Tr>
<TD> table for storing comments: </TD>
<TD colspan = "2">
<Input type = "text" name = "ping_tab" class = "border" size = "30">
</TD>
</Tr>
<Tr>
<TD> administrator username: </TD>
<TD colspan = "2">
<Input type = "text" name = "admin_usn" class = "border" size = "30">
</TD>
</Tr>
<Tr>
<TD> administrator password: </TD>
<TD colspan = "2">
<Input type = "password" name = "admin_pwd" class = "border" size = "30">
</TD>
</Tr>
<Tr>
<TD> confirm the administrator password: </TD>
<TD colspan = "2">
<Input type = "password" name = "admin_pwd2" class = "border" size = "30">
</TD>
</Tr>
<Tr>
<TD> administrator email address: </TD>
<TD colspan = "2">
<Input type = "text" name = "admin_mail" class = "border" size = "30">
</TD>
</Tr>
<Tr>
<TD> Number of articles displayed per page: </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">








Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.