新闻详细页静态化
May 25, 2016 pm 04:59 PM发布新闻,实现新闻页面静态化,真静态
<html> <head>添加新闻</head> <body> <form method="post"action="doadd.php"> 新闻标题:<input type="text"name="title"size="100"><br> 新闻内容:<textarea name="content"cols="100"rows="25"></textarea><br> <input type="submit"name="提交"> </form> </body> </html>
Copy after login
<?php define("HOST","localhost"); define("USER","justfan"); define("PWD","justfan"); define("DB","justfanDB"); define("PORT","3360"); ?>
Copy after login
<?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; } } ?>
Copy after login
<?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>查看刚才添加的新闻</a>"; echo"<a href='add.php'>添加新闻</a>"; ?>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
