PHP index.php include file
I would like to include external php files into my index.php
without using:
index.php?p=pagetoinclude.php
I have it like this now: index.php?page=ho开发者_Go百科me
<- that will include home.php but I have completely forgotten how to do it like this:
index.php/home/
without "?" but using "/" slash instead.
Use mod_rewrite
And I should point out that including a page passed in via GET parameter could be extremely insecure unless you're doing the proper checks.
It looks like you're trying to use fake clear urls.
On index.php you would get the URL, split it at index.php/ and then parse the rest of the string as necessary.
Apache named this kind of feature AcceptPathInfo
:
This directive controls whether requests that contain trailing pathname information that follows an actual filename (or non-existent file in an existing directory) will be accepted or rejected. The trailing pathname information can be made available to scripts in the PATH_INFO environment variable.
For example, assume the location
/test/
points to a directory that contains only the single filehere.html
. Then requests for/test/here.html/more
and/test/nothere.html/more
both collect/more
as PATH_INFO.
You can access that environment variable with $_SERVER['PATH_INFO']
:
Contains any client-provided pathname information trailing the actual script filename but preceding the query string, if available. For instance, if the current script was accessed via the URL
http://www.example.com/php/path_info.php/some/stuff?foo=bar
, then$_SERVER['PATH_INFO']
would contain/some/stuff
.
If you don’t have an Apache web server or can’t use AcceptPathInfo
, you probably can use other mechanisms to rewrite such requests to your file and get the path info part from the requested URI somehow.
精彩评论