1. Operate the implementation according to $_server[' Path_info ').
For example, your site's address is http://127.0.0.1/show_new.php/look-id-1.shtml.
You echo $_server[' Path_info ' come out of the results will be/look-id-1.shtml see this I think you may already understand.
The full demo
index.php
Copy CodeThe code is as follows:
index.php
$conn =mysql_connect ("localhost", "root", "root") or dir ("Connection failed");
mysql_select_db ("Tb_demo", $conn);
$sql = "SELECT * FROM News";
$res =mysql_query ($sql);
Header ("Content-type:text/html;charset=utf-8");
echo "
News list
";
echo "Add News ";
echo "
"; Echo"
| Id |
Title |
View Details |
Modify News |
"While ($row =mysql_fetch_assoc ($res)) {echo"
| {$row [' id ']} |
{$row [' title ']} |
View Details |
Modify Page |
";} The red address above is supposed to be show_news.php?act=look&id={$row [' id ']}echo '
";
Close Resource
Mysql_free_result ($res);
Mysql_close ($conn);
show_new.php page
Copy CodeThe code is as follows:
show_new.php
Header ("Content-type:text/html;charset=utf-8");
$conn =mysql_connect ("localhost", "root", "root");
mysql_select_db ("Tb_demo", $conn);
mysql_query ("Set names UTF8");
$pa = $_server[' path_info ');
//$pa The printed value is/look-id-1.html
//The URL address obtained through regular expression matching
if (Preg_match ('/^\/(look)-(ID)-([\d]) \.shtml$/', $pa, $arr) {
$act = $arr [1];//This is the look method of the request
$id = $arr [3];//This is the ID value obtained
$sql = "SELECT * from news where id= $id";
$res =mysql_query ($sql);
$res = Mysql_fetch_assoc ($res);
Echo $res [' title ']. "". $res [' content '];
}else{
echo "URL address is not valid";
}
Mysql_close ($conn);
See this above I think you must understand that this way with a few of the following for everyone to say the second method of Ah
2. Implement according to the configuration. htaccess.
Let's start with the. htaccess file, create a notepad in the root directory of the Web site and double-click the Save as file name to write
. htaccess, save type Select all files, encode select Utf-8 encoded well this is what you see in the directory of this. htaccess file now
First in Apache Open Mod_rewrite.so,allowoverride None Here are two replacements for allowoverride all
For example, the href address is written one_new-id-1.shtml//This means one_new.php?id=1
This is where the. htaccess can write.
Copy the Code code as follows:
#写你的rewrite规则
Rewriteengine on
# Multiple rules can be configured, the order of matching is from top to bottom
Rewriterule one_new-id-(\d+) \.shtml$ one_new.php?id=$1//Here's the first parameter.
Rewriterule abc_id (\d+) \.html$ error.php
#设置404错误
#ErrorDocument 404/error.php
Your one_new.php page echo $_get[' id ' will definitely output the value of the ID.
Description: This personal ability can only be written here, I will gradually improve
If you have any questions, please leave me a message.
http://www.bkjia.com/PHPjc/326915.html www.bkjia.com true http://www.bkjia.com/PHPjc/326915.html techarticle 1. Operate the implementation according to $_server[' Path_info '). For example, your website's address is http://127.0.0.1/show_new.php/look-id-1.shtml you echo $_server[' Path_info '] come out of the results ...