开发者

How to treat a php file as directory

I wanted to know if it is possible to treat a php file as a directory so that index.php/abc/def really calls index.php. The index.php should then know the subdirectory path (ie /abc/def).

I'm sear开发者_如何学Pythonching a plain php solution. I know that I could use mod_rewrite to map the directory to GET-parameters.


If I recall correctly, you should be able to parse out this info from $_SERVER['PHP_SELF'].

Edit: Even better, take a look at $_SERVER["PATH_INFO"].


This will work if Apache's AcceptPathInfo directive is turned on, which is the default. From the manual:

The treatment of requests with trailing pathname information is determined by the handler responsible for the request. The core handler for normal files defaults to rejecting PATH_INFO requests. Handlers that serve scripts, such as cgi-script and isapi-handler, generally accept PATH_INFO by default.

you can query the path entered using the $_SERVER["PATH_INFO"] directive. You'll have to parse the paths yourself inside the script.


A plain PHP solution is impossible since what is called will be the file.

The PHP in the file does not care where it is or how the file it is in is called other than for include purpose.

What you are looking for is to either convince the OS to pass the /abc/def/ as a parameter to the script or to get the Webserver to do the same thing (ie. mod_rewrite for apache).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜