Release news, realize news page static, True static
add.php
Copy Code code as follows:
<body>
<form method= "POST" action= "doadd.php" >
News title: <input type= "text" name= "title" Size= "><br>"
News content: <textarea name= "Content" cols= "rows=" ></textarea><br>
<input type= "Submit" Name= "submitted" >
</form>
</body>
config.php
Copy Code code as follows:
<?php
Define ("HOST", "localhost");
Define ("USER", "Justfan");
Define ("PWD", "Justfan");
Define ("DB", "justfandb");
Define ("PORT", "3360");
?>
db_class.php
Copy Code code as follows:
<?php
Class DB
{
Private $host = ';
Private $uname = ';
Private $pwd = ';
Private $port = ';
Private $db = ';
public static $instance = null;
Private Function __construct ($host, $uname, $pwd, $port, $db)
{
$this->host = $host;
$this->uname = $uname;
$this->port = $port;
$this->pwd = $pwd;
$this->db = $db;
Mysql_connect ($host, $uname, $pwd);
mysql_select_db ($this->db);
}
public static function Instance ()
{
if (Db:: $instance ==null) {
Include ' config.php ';
Return DB:: $instance = new db (HOST, USER, PWD, PORT, Db);
}
Else
Return Db:: $instance;
}
Public Function query ($sql)
{
mysql_query ("SET NAMES UTF8");
$query = mysql_query ($sql) or Die ($sql. "Error");
if (! $query) return false;
else return $query;
}
Public Function GetAll ($sql)
{
$query = $this->query ($sql);
if ($query)
{
while ($ret = Mysql_fetch_assoc ($query))
{
$result [] = $ret;
}
}
return $result;
}
}
?>
doadd.php
Copy Code code as follows:
<?php
Include ' db_class.php ';
$db = Db::instance ();
$title =$_post["title"];
$content =$_post["Content"];
$num = Uniqid ();
$houzui = ". html";
$filename =date (' Ymd '). ' /'. $num. $houzui;
$sql = "INSERT INTO News (Title,content,path) VALUES (' {$title} ', ' {$content} ', ' {$filename} ')";
$query = $db->query ($sql);
$FP =fopen ("model.htm", "R");
$str =fread ($fp, FileSize ("model.htm"));
$str =str_replace ("{title}", $title, $STR);
$str =str_replace ("{content}", $content, $STR);
Fclose ($FP);
$dir = DirName ($filename);
if (!is_dir ($dir)) {
mkdir ($dir);
}
$handle =fopen ($filename, "w");
Fwrite ($handle, $STR);
Fclose ($handle);
echo "<a href={$filename} target=_blank> View the news </a>" just added;
echo "<a href= ' add.php ' > Add News </a>";
?>
Model.htm
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<script type= "Text/javascript" src= "//code.jquery.com/jquery-1.10.2.min.js" ></script>
<script type= "Text/javascript" src= ". /bootstrap/js/bootstrap.min.js "></script>
<link rel= "stylesheet" href= ". /bootstrap/css/bootstrap.min.css ">
<link rel= "stylesheet" href= ". /bootstrap/css/common.css ">
<title>{title}</title>
<body>
<div class= "Container" >
<div class= "Jumbotron" >
<p>{content}</p>
</div>
</div>
</body>