PHP implements pseudo-static method aggregation and php pseudo-static summary _ PHP Tutorial

Source: Internet
Author: User
PHP implements summary of pseudo-static methods and php pseudo-static summary. PHP implements a summary of pseudo-static methods. php uses pseudo-static methods to hide the passed parameter names. The following describes how PHP implements pseudo-static methods, for more information, see PHP pseudo static summary and php pseudo static summary.

PHP pseudo-static is mainly used to hide the passed parameter names. The following describes the php pseudo-static method. for details, see the following.
Speaking of the pseudo-static implementation scheme, are you very happy to answer "simple, just configure the rewrite rules of apache"

However, have you found this situation? you have recently created many new features. several new features are available every day, and many pseudo-static configurations are available every day before the two-day O & M personnel are happy to cooperate, in two days, the O & M personnel will be scolded. You are paralyzed. why don't you finish this? I am in trouble every day. However, if you want to go online, you have to work hard for the O & M personnel. then, you can say "the last change this time", which will be changed later, ah, your personality is broken down...

If you have such troubles, please read the following article to ensure that you will not seek O & M any more. do whatever you want...

How many methods does PHP implement pseudo-static state? There are four methods for personal opinion and statistics.

1. use apache URL rewriting rules. you can understand how to configure them in apache. here, all the students will create a simple configuration.

RewriteEngine On
RewriteRule ^/test.html index. php? Controller = index & action = test [L]

2. using PHP pathinfo, do you see some websites playing 'www' like this? of course, to support this, you need to set the parameters in 'php. ini'

Set 'CGI. fix_pathinfo' to 1. Take 'www' as an example.

Echo $ _ SERVER ['path _ info']; // output '/c/index/a/test/id/100'
Now, you should understand. you can resolve this section and allocate the actual address.

3. use the 404 mechanism. generally, pseudo-static pages do not actually exist. Therefore, apache 404 can be used for configuration. However, some problems are that requests of the 'post' type will be discarded, you cannot get '$ _ post ',

However, '$ _ get' can still be obtained. assume that the 404 page is '404page. php'. The apache configuration is as follows:

ErrorDocument 404/404 page. php

Then embed the following code in '404page. php ':

Header ("HTTP/1.1 200 OK"); // This must be available. Otherwise, the status is 404 $ reqUrl = $ _ SERVER ['request _ URI ']; // request address/*** resolve the parameter from the URL */function parseUrlParams ($ queryUrl) {$ arr = explode ('? ', $ QueryUrl); parse_str ($ arr [1], $ param); if ($ param) {foreach ($ param as $ key => $ value) {$ _ GET [$ key] = $ value ;}} parseUrlParams ($ reqUrl ); // url resolution parameters // then you can use $ reqUrl to match different actual request addresses based on your own rules if (preg_match ('# ^/test.html # is', $ reqUrl, $ matches) {include ('index. php '); die ();}

4. Improved Method 3. the internal mechanism of method 3 in apache is equivalent to redirection, leading to the inability to obtain parameters passed by post (get. The above analysis is actually unable to find the relevant file, then when the server cannot find the relevant file, we specify a file for it, it will not be OK, it does not need to jump, at this time, POST and so on will not be lost. The apache configuration is as follows:

RewriteEngine On
RewriteCond % {REQUEST_FILENAME }! -F
RewriteCond % {REQUEST_FILENAME }! -D
RewriteRule. index. php

The preceding configuration indicates that the 'Index' in the root directory is used when the requested file or directory cannot be found. php 'alternative, then you can go to 'index. obtain related parameters in php and parse them to the actual request address.

/*** Get the URI address of the current request * @ param void * @ author painsOnline * @ return string URI */function getReqUri () {return trim ($ _ SERVER ["REQUEST_URI"]) ;}$ reqUri = getReqUri (); if (preg_match ('/^ \/test.html/isU', $ reqUri )) {// Parse the request address include 'test. php '; exit ();}

The above content introduces php's pseudo-static method, and I hope it will be helpful to you.

Articles you may be interested in:
  • PHP pseudo-static writing with code
  • PHP pseudo-static page function Appendix usage
  • Use php directly to implement pseudo-static page code without mod_rewrite
  • PHP pseudo-static hiding four methods for passing parameter names
  • Php-based pseudo-static implementation
  • Introduction to PHP pseudo-static technology principles and breakthrough principles
  • Detailed examples of thinkphp routing rules and implementation of pseudo-static functions (apache rewrite)
  • APACHE for php pseudo-static
  • Php pseudo-static IIS
  • APACHE for PHP pseudo-static Rewrite settings
  • Configure pseudo-static for php in Linux

The use of pseudo-static in PHP is mainly to hide the passed parameter names. The following describes how to implement pseudo-static in php. for details, see...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.