Check in PHP if PATH_INFO is enabled on your serve

2020-03-27 08:49发布

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.

标签: php pathinfo
2条回答
Emotional °昔
2楼-- · 2020-03-27 09:22

$_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.

查看更多
家丑人穷心不美
3楼-- · 2020-03-27 09:27

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.

查看更多
登录 后发表回答