這個(gè)類只能php 5.30以上的版本才能使用,繼承了上一個(gè)版本的快速重定向的特點(diǎn)(單獨(dú)類,全部使用靜態(tài)調(diào)用),增添了一個(gè)很重要的功能和屬性 可以調(diào)用 " /> 日本高清无人区影院,理论片午午伦夜理片2021,一本道dvd久久综合高清免费

天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

php快速url重寫更新版[需php 5.30以上]

對(duì)于apache的rewrite模塊打開和設(shè)置則非本文主題,請(qǐng)見其他文章詳解.

這個(gè)類只能php 5.30以上的版本才能使用,繼承了上一個(gè)版本的快速重定向的特點(diǎn)(單獨(dú)類,全部使用靜態(tài)調(diào)用),增添了一個(gè)很重要的功能和屬性 可以調(diào)用其他url中的模塊了 也使得模塊與模塊間或頁面與頁面間的函數(shù)簡(jiǎn)化共享得以實(shí)現(xiàn)

.htaccess文件寫法:
復(fù)制代碼 代碼如下:
#-------------- .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 ---------------



重寫功能引入:讓站點(diǎn)根目錄的index.php末尾寫上下列代碼,重寫就開啟了(正常條件:1.apache的重寫配置成功,且開啟了.htaccess支持的.2.站點(diǎn)根目錄的.htaccess文件設(shè)置好了.3.class.rewrite.php類文件在index.php前面部分加載了.4.頁面模塊文件位置及寫法無誤):
復(fù)制代碼 代碼如下:
//............

Rewrite::__config(
$config['path'],/*'http://xxxxx/mysite/'URL基礎(chǔ)位置*/
$config['md_path'],/*'c:/phpsite/www/mysite/modules/'模塊文件物理目錄*/
array(
'phpinfo'
)
);
Rewrite::__parse();

//..........

模塊文件寫法:

testPk.php
復(fù)制代碼 代碼如下:
<?php
class Rw_testPk extends Rewrite {

//這個(gè)是前導(dǎo)函數(shù),只要訪問到testpk這個(gè)頁面,這個(gè)必然會(huì)執(zhí)行,可用來控制本頁面內(nèi)函數(shù)訪問權(quán)限或本頁面全局變量
public static function init(){
//if (!defined('SITE_PASS')){
echo self::$linktag.'<br/>';//self::$linktag是頁面解析位置路徑值,會(huì)常使用.
//}
}

//當(dāng)訪問"http://localhost/testpk/"時(shí)會(huì)執(zhí)行
public static function index(){
echo 'test';
}

//當(dāng)訪問"http://localhost/testpk/blank"時(shí)會(huì)執(zhí)行或?qū)懽?http://localhost/testpk/index/blank"一般"index/"都是可以被省略的
public static function blank(){}
}
?>

class.rewrite.php;
復(fù)制代碼 代碼如下:
<?php

class Rewrite{

public static $debug = false;//是否打開調(diào)試
public static $time_pass = 0;//獲得模塊文件整體執(zhí)行時(shí)間
public static $version = 2.2;
public static $pretag = 'Rw_';//模塊文件類的名稱前綴

public static $linktag = 'index';//頁面鏈接標(biāo)記,用來標(biāo)記解析的是那個(gè)鏈接,可用來控制各種菜單效果和鏈接訪問權(quán)限

protected static $time_start = 0;
protected static $time_end = 0;
protected static $physical_path = '';//模塊文件的物理路徑
protected static $website_path = '';//模塊文件的站點(diǎn)路徑,因?yàn)榭赡馨颜军c(diǎn)放大站點(diǎn)的子目錄下,如:http://localhost/site/mysite
protected static $ob_contents = '';
protected static $uid = 0;//配合個(gè)人主頁訪問方式 如http://localhost/423/則是訪問http://localhost/profile?uid=423

//允許的系統(tǒng)函數(shù)如$allow_sys_fun=array('phpinfo')那么系統(tǒng)將允許鏈接訪問phpinfo內(nèi)容了,當(dāng)http://localhost/phpinfo或http://localhost/......./phpinfo時(shí)就會(huì)直接執(zhí)行phpinfo這個(gè)函數(shù),不需要phpinfo.php模塊文件
private static $allow_sys_fun = array();

private static function __get_microtime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}


//設(shè)置調(diào)試Rewrite::__debug(true);
public static function __debug($d = true){
static::$debug = $d;
}

//配置路徑和允許函數(shù)
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;
}

//調(diào)試函數(shù)
public static function __msg($str){
if(static::$debug){
echo "/n<pre>/n".print_r($str,true)."/n</pre>/n";
}
}

//解析開始時(shí)間
public static function __start(){
self::$time_start = self::__get_microtime();
}

//解析結(jié)束時(shí)間
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');
}
}

//內(nèi)部跨模塊url解析調(diào)用,如在test1.php模塊頁面中執(zhí)行了Rwrite::__parseurl('/test2/show')這句,將調(diào)用test2.php模塊頁面中的show方法(Rw_test2這個(gè)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);
}
}
}
}
}

//核心鏈接解析函數(shù)Rwrite::__parse();在頂級(jí)重寫核心定向目標(biāo)index.php中的執(zhí)行,意味著Rwrite自定義重寫開啟
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():preg_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{

//這個(gè)地方是對(duì)"個(gè)人主頁"的這種特殊鏈接定向到"profile/"了,可自己修改
//如:www.xxx.com/12/將表示www.xxx.com/profile/?uid=12或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();
}

//這里是用戶自定義鏈接的解析(用數(shù)據(jù)庫存儲(chǔ)的解析值) 如: xiaoming.baidu.com

//數(shù)據(jù)庫中 xiaoming這個(gè)標(biāo)簽指向一個(gè)人的博客 就會(huì)到了www.baidu.com/blog?uid=12或www.baidu.com/blog?uname=xiaoming(這個(gè)就看自己咋設(shè)計(jì)數(shù)據(jù)庫了)

public static function __goto($para = '',$path = ''){
$w = static::$website_path;
if(empty($para)){
exit('未知鏈接,解析失敗,不能訪問');
}
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();
}
}
}
?>

php技術(shù)php快速url重寫更新版[需php 5.30以上],轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 国产三级在线观看免费 | 葵司中文第一次大战黑人 | 国产又黄又粗又爽又色的视频软件 | 2023国产精品一卡2卡三卡4卡 | 蜜柚免费视频高清观看在线 | 国产91专区 | 97精品在线观看 | bl 纯肉 高Hbl被强文 | 百度影音第四色 | 日本欧美高清一区二区视频 | 国产欧美另类久久久精品免费 | 国产精品资源网站在线观看 | 国产手机在线亚洲精品观看 | 日韩精品无码视频一区二区蜜桃 | 久久国产精品麻豆AV影视 | 国产久久re6免费热在线 | 九九久久国产精品免费热6 九九久久国产精品大片 | 人妻少妇69式99偷拍 | 国产成人在线播放视频 | 伊人影院综合网 | 青青草干免费线观看 | 一本之道高清www在线观看 | 国产福利高清在线视频 | 92精品国产成人观看免费 | 一区二区三区无码被窝影院 | 校园全肉高h湿一女多男 | 在线欧美 精品 第1页 | 亚洲h视频在线观看 | 久久精品国产视频澳门 | 国产97视频在线观看 | 亚洲伊人情人综合网站 | 2020无码最新国产在线观看 | 国产精品一区二区亚瑟不卡 | 91亚洲 欧美 国产 制服 动漫 | 美女扒开尿口直播 | 99国产在线视频 | 国产99小视频| 久久午夜伦理 | 六度影院最新 | 伊人久久大香线蕉综合电影 | 亚洲人日本人jlzzy |