


A brief discussion on implementing pseudo-static in PHP_PHP tutorial
/**********************
Title: A brief discussion on pseudo-static implementation in PHP
Author:insun
Blog:http://yxmhero1989.blog.163.com
Reference:
PHP implements pseudo-static url http://blog.78999.org/php_sql_asp/php-rewrite.html
php pseudo-static (url rewrite) apache configuration http://hi.baidu.com/%B9%D6%CA%AF/blog/item/2659b6af548923d57cd92ab9.html
Three ways to implement PHP pseudo-static pages: http://www.BkJia.com/kf/201108/100056.html
Implementation of friendly URL (recommended for vomiting blood) http://www.BkJia.com/kf/201006/49208.html
The specific implementation method of pseudo-static page in PHP http://www.BkJia.com/kf/201108/100058.html
PHP pseudo-static and anti-injection http://www.BkJia.com/Article/201108/100059.html
Php parameter passing and more reasonable arrangements after PHP obtains url parameters http://hi.baidu.com/wd1314521/blog/item/3af604822f1938b70df4d2e3.html
Two methods of php to implement pseudo-static pages (including two methods of url rewriting http://hi.baidu.com/newyorkmen/blog/item/f998131ae4121b0d34fa4167.html/cmtid/ 6becf7c0d5fd6d38e4dd3b08 PHP page implementation static explanation and detailed code http://hi.baidu.com/newyorkmen/blog/item/f387e3b723dddac437d3ca66.html
*/
I recently interned in a company. I used a PHP crawler to crawl website pages and save them to the database. Then I wrote a website to call the database, and then performed SEO, requiring collection, remote data localization, pseudo-static, keyword optimization, no dead links and no islands. ; After finishing, you can join the project team.
The pseudo-static implementation of PHP is actually for SEO (Search Engine Optimization), which means that spiders like Google and Baidu don't like dynamic pages, so when you display them, they are displayed as .html or directories. In fact, it is a php file on the server side. In other words, search engines do not like pages like /page.php?id=4, but like pages like /4.html, which are very friendly to them (conducive to inclusion). Of course, you will not directly create N pieces of html page.
one. So the easiest way
URL rewriting (pseudo-static) under Apache+PHP
1. Check if apache supports mod_rewrite
Look for LoadModule rewrite_module modules/mod_rewrite.so in apache's httpd.conf and remove the # in front of it (if there is one, uncomment it). Under Linux, it is recommended to use the Xampp installation package, which The LoadModule has basically been uncommented, so there is generally no need to change it.
Then use phpinfo() to check the environment configuration and see if mod_rewrite is supported. As shown in the picture:

2. Find Options FollowSymLinks in http.conf and change the AllowOverride None to AllowOverride All.
At this time, the troops are divided into two groups. Those with http.conf permissions can add url rewrite rules after http.conf
Such as
RewriteEngine On
RewriteRule ^(.*)/([0-9]{1,}).html$ $1/page.php?id=$2
The second way is to create an .htaccess file in the code root directory. This file is relatively simple to create. There are three methods. The simplest is of course to create 1.htaccess and then open it in Notepad and save it as .htaccess. The other is to rename and ftp under cmd. Software modifications.
3.rewrite rules
Just look at an example and you’ll understand
RewriteEngine On
RewriteRule ^(.*)/([0-9]{1,}).html$ $1/page.php?id=$2
$ is the terminator, write a regular expression in front, $1 gets the first sub-pattern (the stuff inside the parentheses), $2 gets the second sub-pattern stuff.
Friendly reminder ^ is the beginning, don’t forget to add
If there are 2 parameters, it is very simple and you can handle it yourself.
That is to say, if the browser displays 4.html (the link in your file is written as .html), the actual call is page.php?id=4, so that the input fields of the browser are all html, achieving Pseudo-static.
Of course, if you rewrite different regular rules, the displayed url will be different, whichever you like.
Don't add semicolons when you encounter multiple lines. The following is correct:
RewriteEngine On
RewriteRule ^(.*)/([0-9]{1,}).html$ $1/page.php?id=$2
RewriteRule ^(.*)/index.html$ $1/index.php
RewriteRule ^(.*)/wenzhang.html$ $1/wenzhang.php
RewriteRule ^(.*)/gushi.html$ $1/gushi.php
RewriteRule ^(.*)/sanwen.html$ $1/sanwen.php
RewriteRule ^(.*)/zawen.html$ $1/zawen.php
RewriteRule ^(.*)/shige.html$ $1/shige.php
RewriteRule ^(.*)/riji.html$ $1/riji.php
RewriteRule ^(.*)/xiaoshuo.html$ $1/xiaoshuo.php
RewriteRule ^(.*)/contact.html$ $1/contact.php
<code style="line-height: 22px"><font face="新宋体">The overview is the URL rewriting engine and specifying some rewriting rules<code style="line-height: 22px"><code style="line-height: 22px"><font face="新宋体">综述就是网址重写引擎和指定一些重写规则</font>
., try Faking URL Suffix (fake URL suffix)
, it looks very static, which improves security and SEO friendliness.
4. Restart apache.
Windows httpd.conf is easy to find, it is in the conf directory (I mean if you don’t use the integration package)
Linux has httpd.conf in the opt/lampp/etc directory (generally, it is recommended to use Xampp according to the package under Linux and install it in the opt directory)
Perform the same work as above and restart and it will be ok
login as: root
Server refused our key
root@XXXXX.com's password:
Last login: Thu Jul 21 14:26:26 2011 from 112.65.219.75
[root@XXXXX ~]# who
root pts/0 2011-07-21 14:32 (112.65.219.75)
[root@XXXXX ~]# /opt/lampp/lampp restart
Stopping XAMPP for Linux 1.6.4...
XAMPP: Stopping Apache with SSL...
XAMPP: Stopping MySQL...
XAMPP: Stopping ProFTPD...
XAMPP stopped.
Starting XAMPP for Linux 1.6.4...
XAMPP: Starting Apache with SSL (and PHP5)...
XAMPP: Starting MySQL...
XAMPP: Starting ProFTPD...
XAMPP for Linux started.
Just wait.
5. Partial code guidance:
echo ""; ";
$i=$row['id'];//The id column in the database table insun4, for. . . .
echo " ".$row['title']."
";
//echo " ".$row['title']."
";
//echo " ".$row['description']."
";
echo " ".$row['description']."
";
echo "
?>
include 'config.php';
set_time_limit(0);//Prevent timeout errors from being displayed.
mysql_query("set names'gbk'");//utf8
//$url = "http://www.jj59.com/";
$gid = $_GET['id'];
$query="select * from insun4 where id = $gid";//Selective output using like.where link like'http://www.jj59.com/yuanchuang/%'
//echo $query;
$queryresult=mysql_query($query) or die("查询数据失败");//执行查询
//echo var_dump($queryresult);
while($row = mysql_fetch_array($queryresult)){
echo ($row['content'])."
";
}
?>
RewriteEngine On
RewriteRule ^(.*)/([0-9]{1,}).html$ $1/page.php?id=$2
RewriteRule ^(.*)/index.html$ $1/index.php
RewriteRule ^(.*)/wenzhang.html$ $1/wenzhang.php
RewriteRule ^(.*)/gushi.html$ $1/gushi.php
RewriteRule ^(.*)/sanwen.html$ $1/sanwen.php
RewriteRule ^(.*)/zawen.html$ $1/zawen.php
RewriteRule ^(.*)/shige.html$ $1/shige.php
RewriteRule ^(.*)/riji.html$ $1/riji.php
RewriteRule ^(.*)/xiaoshuo.html$ $1/xiaoshuo.php
RewriteRule ^(.*)/contact.html$ $1/contact.php
二,看到网上有2-3个方法,都是写个Url_rewrite函数,然后require的,感觉不好就不推荐大家了,大家可以去搜索下。
一般都是借助于apache,nginx,htaccess等,很少用php来实现url的静态化,用php来实现静态化比较麻烦。
如果出现下面这样,说明你没配置好。

如果出现下面这样,说明你配置好了,只是rewrite规则写的不对,检查下好了。

If the following appears, congratulations.



TomodifydatainaPHPsession,startthesessionwithsession_start(),thenuse$_SESSIONtoset,modify,orremovevariables.1)Startthesession.2)Setormodifysessionvariablesusing$_SESSION.3)Removevariableswithunset().4)Clearallvariableswithsession_unset().5)Destroythe

Arrays can be stored in PHP sessions. 1. Start the session and use session_start(). 2. Create an array and store it in $_SESSION. 3. Retrieve the array through $_SESSION. 4. Optimize session data to improve performance.

PHP session garbage collection is triggered through a probability mechanism to clean up expired session data. 1) Set the trigger probability and session life cycle in the configuration file; 2) You can use cron tasks to optimize high-load applications; 3) You need to balance the garbage collection frequency and performance to avoid data loss.

Tracking user session activities in PHP is implemented through session management. 1) Use session_start() to start the session. 2) Store and access data through the $_SESSION array. 3) Call session_destroy() to end the session. Session tracking is used for user behavior analysis, security monitoring, and performance optimization.

Using databases to store PHP session data can improve performance and scalability. 1) Configure MySQL to store session data: Set up the session processor in php.ini or PHP code. 2) Implement custom session processor: define open, close, read, write and other functions to interact with the database. 3) Optimization and best practices: Use indexing, caching, data compression and distributed storage to improve performance.

PHPsessionstrackuserdataacrossmultiplepagerequestsusingauniqueIDstoredinacookie.Here'showtomanagethemeffectively:1)Startasessionwithsession_start()andstoredatain$_SESSION.2)RegeneratethesessionIDafterloginwithsession_regenerate_id(true)topreventsessi

In PHP, iterating through session data can be achieved through the following steps: 1. Start the session using session_start(). 2. Iterate through foreach loop through all key-value pairs in the $_SESSION array. 3. When processing complex data structures, use is_array() or is_object() functions and use print_r() to output detailed information. 4. When optimizing traversal, paging can be used to avoid processing large amounts of data at one time. This will help you manage and use PHP session data more efficiently in your actual project.

The session realizes user authentication through the server-side state management mechanism. 1) Session creation and generation of unique IDs, 2) IDs are passed through cookies, 3) Server stores and accesses session data through IDs, 4) User authentication and status management are realized, improving application security and user experience.


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

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

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.
