PHP实现Mod Rewrite重定向功能

| 1 Comment | No TrackBacks

APACHERE_WRITE设置实在是很复杂,找了很久,终于找到了这个用PHP仿制实现的功能:

传递参数:http://localhost/websamples/rewrite.php/name/hua/sex/male

解析参数:

得到的参数串 /name/hua/sex/male
Array ( [0] => name [1] =>
hua[2] => sex [3] => male )

-------------------------------------------------------------------------------------------

<?php

/* 此方法仅用于apache服务器 */

if(isset($_SERVER[PATH_INFO])) //PATH_INFO可用,注意apache2默认不可用

  $query_string = $_SERVER[PATH_INFO];

else {

  $query_string = str_replace($_SERVER[SCRIPT_NAME],"",$_SERVER[PHP_SELF]);

  //

  $query_string = str_replace($_SERVER[SCRIPT_NAME],"",$_SERVER[REQUEST_URI]);

}

if(empty($query_string))

  echo "没有参数";

else {

  echo "得到的参数串 $query_string<br>";

  $args = split("/",substr($query_string,1)); //分裂成数组

  print_r($args); // 查看得到的参数数组。注意由于传递的参数没有变量名信息,你需要仔细的按位置确定参数的含义

}

?>

No TrackBacks

TrackBack URL: http://www.wujianrong.com/mt-tb.cgi/1372

1 Comment

感觉蛮不错的,谢了

Leave a comment

About this Entry

This page contains a single entry by kevinwu published on November 11, 2006 12:22 AM.

Hotmail的邮箱空间升到2G了 was the previous entry in this blog.

Apache模块 mod_rewrite is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.