I'm introducing a RegEx based URI router to a legacy PHP codebase and some requests still need to be handled the old way (by loading a .php
file) before the transition can be completed.
The router is working fine and I can build the .php
file path for the requests that will be handled this way. How can I, given the PHP file path, delegate the request entirely to this file?
I thought a simple require $filepath;
would do but I'm getting include errors from that script when it tries to include other files.
I tried some ideas without success:
$_SERVER['SCRIPT_FILENAME'] = $sControllerPath;
set_include_path(get_include_path().PATH_SEPARATOR.dirname($sControllerPath));
require $sControllerPath;
You may have to change directory to the dirname($sControllerPath);
if it uses relative includes.
$_SERVER['SCRIPT_FILENAME'] = $sControllerPath;
set_include_path(get_include_path().PATH_SEPARATOR.dirname($sControllerPath));
// for relative includes like ./file.php
chdir(dirname($sControllerPath));
require $sControllerPath;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.