The content of this article is about the fool-like php mysql pseudo-static (real existing html page), which has a certain reference value. Now I share it with everyone. Friends in need can refer to it
Everyone should know about pseudo-static
For example, the page generated by your php page is xxx.php?id=1
For SEO and easy crawling by search engines such as Baidu, and to prevent server resources from being occupied during high concurrency
We should display the link to the xxx.php?id=1 page as xxx_1.html or other similar formats, anyway, the .html suffix is.
I didn't delve into this myself, but I implemented this briefly.
1 A simple list
<?php //连接数据库 $con = mysql_connect("localhost","root","root"); //选择数据库 mysql_select_db("test", $con); //查询数据库 $result = mysql_query("SELECT * FROM list"); //遍历输出数据库 while($row = mysql_fetch_array($result)) { $url = $row["url"]; $id = $row["id"]; if(empty($url)){ echo "<a href='p.php?id=$id'/>$row[title]</a><br/>"; }else{ echo "<a href='http://localhost/20180417/$url'/>$row[title]</a><br/>"; } } mysql_close($con); ?>
As shown in the picture:
The important thing is that the p.php page
queries the database url field, if it is empty , then start file_get_contents to obtain the html code of the entire page, and then write the code to an html file named LKY_$id.html, where $id is the id of the current page. If the current page id=1, then the generated The file name is LKY_1.html, and then the file name is updated to the url field of the database
<!DOCTYPE html> <html> <head> </head> <body> <?php //连接数据库 $con = mysql_connect("localhost","root","root"); //选择数据库 mysql_select_db("test", $con); //获得id $id =$_GET["id"]; //查询数据库 $result = mysql_query("SELECT * FROM list where id =".$id); //遍历输出数据库 while($row = mysql_fetch_array($result)) { $url = $row["url"]; if(empty($url)){ $get_html = "http://localhost/20180417/get_html.php?id=$id"; $html_utl = "LKY_$id.html"; $con_html = file_get_contents($get_html); $html = fopen($html_utl, "w"); fwrite($html, $con_html); fclose($html); echo $row["zhengwen"]; mysql_query("UPDATE list SET url = '$html_utl' WHERE id = '$id'"); }else{ echo $row["zhengwen"]; } } mysql_close($con); ?> </body> </html>
When the user accesses xxx.p.php?id=1, the database will be queried. If the url field is empty, then the html of the entire page is obtained. The source of the html page is obtained using a get_html.php
<!DOCTYPE html> <html> <head> </head> <body> <?php //连接数据库 $con = mysql_connect("localhost","root","root"); //选择数据库 mysql_select_db("test", $con); //获得id $id =$_GET["id"]; //查询数据库 $result = mysql_query("SELECT * FROM list where id =".$id); //遍历输出数据库 while($row = mysql_fetch_array($result)) { echo $row["zhengwen"]; } mysql_close($con); ?> </body> </html>
After obtaining it, generate the html file and save it in the directory specified by us on the server. If you access xxx.p.php?id=1 and judge that the url field is not empty, then directly output the page data or jump to LKY_1.html
Then a corresponding judgment is made in the list on the homepage to determine whether the url is empty. If it is empty, the output is the hyperlink of p.php?id=1, otherwise from the database Take the html file name of the url field and output LKY_1.html
# What I want to say is that this is actually generating html files!
#
The above is the detailed content of Foolish php+mysql pseudo-static (real html page). For more information, please follow other related articles on the PHP Chinese website!