Check in PHP if PATH_INFO is enabled on your serve

2020-03-27 08:46发布

问题:

From PHP, is there a cross-platform, cross-web server way of determining if PATH_INFO is enabled on the server you are running on?

It appears $_SERVER['PATH_INFO'] is only populated if there are extra path segments after the script, so you can't reliably tell if PATH_INFO is enabled if the request is for /index.php, for example.

回答1:

I don't think there is a defined way to get hold of an Apache configuration value like that.

One idea that comes to mind is making a request using file_get_contents() to

http://current_site_domain/check.php/test

check.php would output $_SERVER['PATH_INFO'].

If the result of the request is "test", PATH_INFO works.

Of course, this might fail because opening URLs is disabled, because you don't know the local domain, because there's a firewall in place, etc. etc.

Another way that is less prone to failing is using an iframe:

<iframe src="/check.php/It%20works!"></iframe>

If you see "it works" inside the ifrane, PATH_INFO works. Possibly useful for an installation procedure.



回答2:

$_SERVER["PATH_INFO"] should always be available. If it's not, it just means there was no extra information between the file name and the query string.



标签: php pathinfo