PHP+MYSQL article management system (1)_PHP tutorial
#############################################
This article is original. If quoted, please indicate the author's information.
Email: leo_cdp@yeah.net
http://www.cfeng.net/
The code of this article may be reproduced at will, please keep this statement when using it
########### ##################################
I wrote a text management document last year and I still feel a little uncomfortable. In addition, I applied for a host, so I wrote PHP+MYSQL to manage the article during the test period
With the support of the majority of netizens, the code is now released
Function description:
Basic operations of the article: add, modify, lock, Unlock, recommend, delete and wait
and has powerful functions such as search, comment, recommend to friends, etc., with emphasis on security, beautiful interface and humanized design.
Main file list:
setup.php Installation program, you can use this system after running it!
index.php Display
manager.php Add and manage articles.
change.php Operation on existing articles.
edit_article.php Article modification
commend.php Recommend the article to friends.
read_article.php article reading.
ping.php Post comments on articles.
search.php Article search
type_manager.php Type management
login.php Administrator login.
config.php Main configuration file
func.php Function file
footer.inc, header.inc, nav.inc include files.
list.txt Type list
and some other peripheral programs
Management system demonstration address:
http://www.cfeng.net/article/
######## ################config.php Main configuration file #########################
$host="localhost"; 🎜>$database="cfeng.net"; 🎜> $admin_usn="leo"; En> $ pagenum = "20"; ## Display the number of articles per page
$ sess = md5 ($ admin_usn. $ Admin_pwd); ##################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_0230a09a07cab1df8112d00b1f9a9719"))
{
if($sess_0230a 09a07cab1df8112d00b1f9a9719!=$sess)
redir("login.php"); location:$addr");
}
function add_article()##This system implements wide entry and strict exit, so adding articles seems a little simple!
{
global $database,$table,$title,$cont,$type,$html;
$dat=date(Y year m month d day);
$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 the number of views!
{
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 recommended 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 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 article!
{
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=" $file_cont.="$host="$host";#your database server addressn";
$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 "配置完成正检测各选项的正确性
";
else echo "文件写入错误,请检测文件所在目录的权限
";
fclose($fp);
echo "正在检测数据连接.........." ;
if(@mysql_connect("$host","$database_usn","$database_pwd"))
{
echo "成功!
" ;
$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 建立成功
".mysql_error();
else
echo"数据库 $table 建立失败
";
$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),
) ");
If (mysql_db_qury ($ database, $ query))
{
Echo" User Review Database $ Ping_tab successfully & lt; BR>Congratulations, the article management system has been successfully installed! Please go here for basic settings!
"; ","r");
$file_cont=fread($fp,filesize("setup.php"));
$file_cont=" nsession_start();nrequire"./inc/func. php";n check_login();n?>n".$file_cont; 🎜> 🎜> echo "Database connection failed !Please check the correctness of your username and password!
";
exit();
}
require "./inc/header.inc";
?>
require "./inc/nav.inc";?>

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

TooptimizePHPapplicationsforperformance,usecaching,databaseoptimization,opcodecaching,andserverconfiguration.1)ImplementcachingwithAPCutoreducedatafetchtimes.2)Optimizedatabasesbyindexing,balancingreadandwriteoperations.3)EnableOPcachetoavoidrecompil

DependencyinjectioninPHPisadesignpatternthatenhancesflexibility,testability,andmaintainabilitybyprovidingexternaldependenciestoclasses.Itallowsforloosecoupling,easiertestingthroughmocking,andmodulardesign,butrequirescarefulstructuringtoavoidover-inje

PHP performance optimization can be achieved through the following steps: 1) use require_once or include_once on the top of the script to reduce the number of file loads; 2) use preprocessing statements and batch processing to reduce the number of database queries; 3) configure OPcache for opcode cache; 4) enable and configure PHP-FPM optimization process management; 5) use CDN to distribute static resources; 6) use Xdebug or Blackfire for code performance analysis; 7) select efficient data structures such as arrays; 8) write modular code for optimization execution.

OpcodecachingsignificantlyimprovesPHPperformancebycachingcompiledcode,reducingserverloadandresponsetimes.1)ItstorescompiledPHPcodeinmemory,bypassingparsingandcompiling.2)UseOPcachebysettingparametersinphp.ini,likememoryconsumptionandscriptlimits.3)Ad


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools
