More than 5.30 of the version can be used, inherited the characteristics of the previous version of the fast redirection (separate classes, all using static calls), add a very important function and properties, can invoke other URLs in the module, but also the module and the module or the function of the page and the page to simplify the sharing can be implemented. htaccess file notation:
- #--------------. htaccess start---------------
- Rewriteengine on
- Rewriterule!. (js|ico|gif|jpg|png|css|swf|htm|txt) $ index.php
- Php_flag MAGIC_QUOTES_GPC off
- Php_flag register_globals off
- #--------------. htaccess End---------------
Copy CodeRewrite feature introduction: Let the index.php at the end of the site root write the following code, the rewrite is turned on (normal condition: 1.apache rewrite configuration succeeded, and turned on. htaccess supported. 2. The. htaccess file for the site root is set. The 3.class.rewrite.php class file is loaded in the previous section of index.php. 4. Page module file location and correct format): The code is as follows:
- //............
- Rewrite::__config (
- $config [' Path '],/* ' http://xxxxx/mysite/' URL base location */
- $config [' Md_path '],/* ' c:/phpsite/www/mysite/modules/' module file physical directory */
- Array
- ' Phpinfo '
- )
- );
- Rewrite::__parse ();
- //..........
Copy CodeModule file notation: testpk.php
- Class Rw_testpk extends Rewrite {
- This is a leading function, as long as the access to TESTPK this page, this is bound to execute, can be used to control this page function access rights or the page global variables
- public static function init () {
- if (!defined (' Site_pass ')) {
- echo Self:: $linktag. '
';//self:: $linktag is the page resolution location path value, which is often used.
- //}
- }
- When access to "http://bbs.it-home.org/testpk/" is performed
- public static function index () {
- echo ' Test ';
- }
- When accessing "Http://bbs.it-home.org/testpk/blank" will be executed or written "Http://bbs.it-home.org/testpk/index/blank" General "index/" can be omitted
- public static function blank () {}
- }
- ?>
Copy Codeclass.rewrite.php; code as follows:
- Class rewrite{
- public static $debug = false;//Whether debugging is turned on
- public static $time _pass = 0;//Gets the overall execution time of the module file
- public static $version = 2.2;
- public static $pretag = ' rw_ ';//name prefix of module file class
- public static $linktag = ' index ';//page link tag, which is used to mark the parsing of the link, which can be used to control various menu effects and link access rights
- protected static $time _start = 0;
- protected static $time _end = 0;
- protected static $physical _path = ";//physical path to the module file
- protected static $website _path = ";//The site path of the module file, as it may be the site to enlarge the subdirectory of the site, such as: Http://bbs.it-home.org/site/mysite
- protected static $ob _contents = ";
- protected static $uid = 0;//with personal page access as http://bbs.it-home.org/423/is Access http://bbs.it-home.org/profile?uid=423
- Allowed system functions such as $allow_sys_fun=array (' phpinfo ') then the system will allow links to access phpinfo content, when Http://bbs.it-home.org/phpinfo or http:// Bbs.it-home.org/......./phpinfo directly executes phpinfo This function, does not need phpinfo.php module file
- private static $allow _sys_fun = Array ();
- private static function __get_microtime () {
- List ($usec, $sec) = Explode ("", Microtime ());
- return (float) $usec + (float) $sec);
- }
- Set Debug Rewrite::__debug (True);
- public static function __debug ($d = True) {
- Static:: $debug = $d;
- }
- Configure paths and Allow functions
- public static function __config ($website _path = ", $physical _path =", $allow _sys_fun = Array ()) {
- Self:: $physical _path = $physical _path;
- Self:: $website _path = $website _path;
- Self:: $allow _sys_fun = $allow _sys_fun;
- }
- debugging functions
- public static function __msg ($STR) {
- if (static:: $debug) {
- echo "n
N ". Print_r ($str, true)." N n ";
- }
- }
- Parse Start time
- public static function __start () {
- Self:: $time _start = Self::__get_microtime ();
- }
- Parse End time
- public static function __end ($re = False) {
- Self:: $time _end = Self::__get_microtime ();
- Self:: $time _pass = Round ((self:: $time _end-self:: $time _start), 6) * 1000;
- if ($re) {
- Return self:: $time _pass;
- }else{
- Self::__msg (' Pass_time: '. Self:: $time _pass. ' Ms ');
- }
- }
- Internal cross-module URL resolution calls, such as executing rwrite::__parseurl ('/test2/show ') in the Test1.php module page, will invoke the Show method in the Test2.php module page (rw_ Test2 the method of this class)
- public static function __parseurl ($url = ", $fun =", $data = NULL) {
- if (!empty ($url) &&!empty ($fun)) {
- $p = static:: $physical _path;
- if (File_exists ($p. $url) | | file_exists ($p. $url. php ')) {
- $part = Strtolower (basename ($p. $url, '. php '));
- Static:: $linktag = $part. ' /'. $fun;
- $fname = static:: $pretag. $part;
- if (Class_exists ($fname, false)) {
- if (Method_exists ($fname, $fun)) {
- Return $fname:: $fun ($data);
- }
- }else{
- Include ($p. $url);
- if (Class_exists ($fname, False) && method_exists ($fname, $fun)) {
- Return $fname:: $fun ($data);
- }
- }
- }
- }
- }
- Core link parsing function rwrite::__parse (); Overriding the execution of the core-directed target index.php in the top-level, means that the Rwrite custom override is turned on
- public static function __parse ($Url = ") {
- Self::__start ();
- $p = static:: $physical _path;
- $w = static:: $website _path;
- $req _execute = false;
- $url _p = Empty ($URL)? $_server[' Request_uri ': $Url;
- $local = Parse_url ($w);
- $req = Parse_url ($url _p);
- $req _path = preg_replace (' |[ ^w/.]| ', ', $req [' Path '];
- $req _para = Empty ($URL)? Strstr ($_server[' server_name '], '. ', true): ' www ';
- if (Empty ($URL) && substr_count ($_server[' server_name '), '. ') = = 2 && $req _para! = ' www ') {
- Self::__goto ($req _para,preg_replace (' |^ '. $local [' path ']. ' | ', "", $req _path));
- return;
- }else{
- $req _path_arr = Empty ($req _path)? Array ():p reg_split ("|[ /]+| ", Preg_replace (' |^ '. $local [' path ']. ' | '," ", $req _path));
- $req _fun = Array_pop ($req _path_arr);
- if (substr ($req _fun,0,2) = = ' __ ') {
- $req _fun = substr ($req _fun,2);
- }
- $req _path_rearr = Array_filter ($req _path_arr);
- Self::__msg ($req _path_rearr);
- $req _temp = implode ('/', $req _path_rearr);
- $fname = $req _temp. ' /'. $req _fun;
- if (!empty ($req _fun) &&in_array ($req _fun,static:: $allow _sys_fun)) {
- $req _fun ();
- }else{
- if (!empty ($req _fun) &&file_exists ($p. $fname. php ')) {
- Include ($p. $fname. php ');
- }else{
- $fname = Empty ($req _temp)? ' Index ': $req _temp;
- if (File_exists ($p. $fname. php ')) {
- Include ($p. $fname. php ');
- }else{
- $fname = $req _temp. ' /index ';
- if (File_exists ($p. $fname. php ')) {
- Include ($p. $fname. php ');
- }else{
- This place is directed to "profile/" for this special link to "personal homepage" and can be modified by itself
- such as: www.xxx.com/12/will represent www.xxx.com/profile/?uid=12 or www.xxx.com/profile?uid=12
- $uid = Is_numeric ($req _temp)? $req _temp:strstr ($req _temp, '/', true);
- $ufun = Is_numeric ($req _temp)? ' Index ': strstr ($req _temp, '/');
- if (Is_numeric ($uid)) {
- Self:: $uid = $uid;
- if (!isset ($_get[' uid '))) $_get[' uid '] = $uid;
- $fname = ' profile/'. $ufun;
- if (File_exists ($p. $fname. php ')) {
- Include ($p. $fname. php ');
- }else{
- Header ("Location:". $w);
- Exit ();
- }
- }else if (file_exists ($p. ' index.php ')) {
- $fname = ' index ';
- Include ($p. ' index.php ');
- }else{
- Header ("Location:". $w);
- Exit ();
- }
- }
- }
- }
- $ev _fname = Strrpos ($fname, '/') ===false? $fname: substr ($fname, Strrpos ($fname, '/') +1);
- $ev _fname = static:: $pretag. $ev _fname;
- if (class_exists ($ev _fname, False) && method_exists ($ev _fname, $req _fun)) {
- Static:: $linktag = $req _fun== ' index '? $fname. ' /': $fname. ' /'. $req _fun;
- if ($req _fun! = ' init ' && method_exists ($ev _fname, ' init ')) {
- $ev _fname::init ();
- }
- $ev _fname:: $req _fun ();
- }else if (class_exists ($ev _fname, False) && method_exists ($ev _fname, ' index ')) {
- Static:: $linktag = $fname. ' /';
- if (method_exists ($ev _fname, ' init ')) {
- $ev _fname::init ();
- }
- $ev _fname::index ();
- }else if ($fname! = ' index ' && class_exists (static:: $pretag. ' Index ', false) && method_exists (static::$ Pretag. ' Index ', ' index ') {
- $ev _fname = static:: $pretag. ' Index ';
- Static:: $linktag = ' index/';
- if (method_exists ($ev _fname, ' init ')) {
- $ev _fname::init ();
- }
- $ev _fname::index ();
- }else{
- Self::__msg (' Function not exist! ');
- }
- }
- }
- Self::__end ();
- }
- Here is the resolution of the user-defined link (with the parsed value stored in the database) such as: xiaoming.baidu.com
- Database Xiaoming This tag to a person's blog will go to the www.baidu.com/blog?uid=12 or www.baidu.com/blog?uname=xiaoming (this depends on how you design the database)
- public static function __goto ($para = ', $path = ') {
- $w = static:: $website _path;
- if (empty ($para)) {
- Exit (' Unknown link, parse failed, cannot access ');
- }
- if (class_exists (' parseURL ')) {
- $prs = Parseurl::selectone (Array (' tag ', ' = ', $para));
- Self::__msg ($PRS);
- if (!empty ($prs)) {
- $PARASTR = $prs [' tag '];
- $output = Array ();
- $_get[$prs [' idtag ']] = $PRS [' id '];
- Parse_str ($prs [' parastr '], $output);
- $_get = Array_merge ($_get, $output);
- $path = $prs [' type ']. ' /'. Preg_replace (' |^/'. $prs [' type ']. ' | ', ', $path);
- Self::__msg ($path);
- Header (' Location: '. $w. $path. '? '. Http_build_query ($_get));
- Exit ();
- }else{
- Header ("Location:". $w);
- Exit ();
- }
- }else{
- Header ("Location:". $w);
- Exit ();
- }
- }
- }
- ?>
Copy Code |