$_SERVER[“SCRIPT_URL”]: when is it reliably present?

我与影子孤独终老i 提交于 2019-12-23 07:59:11

问题


In my local environment (PHP 5.4.24 on Apache 2.2.26) $_SERVER["SCRIPT_URL"] is present, but I read around that this variable is not always present, even though I couldn't find exactly when it is and when it isn't.

I'd like to know what is required for this variable to be reliably present.


回答1:


It's only available when you have mod_rewrite enabled:

http://httpd.apache.org/docs/2.0/rewrite/rewrite_intro.html#EnvVar




回答2:


This variable strongly depends on the server's configuration.

When using nginx with php5-fpm (fcgi) for example, you'd pass the variable as fpm_parameter:

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

There is a similiar configuration for scgi.

There are 3 types of global variables in $_SERVER, some are taken from the client's request header and are not reliable, some are set by PHP/Webserver (for example REMOTE_ADDR) and are very reliable, and some depend on your configuration which can be reliable depending on that configuration.



来源:https://stackoverflow.com/questions/24428981/serverscript-url-when-is-it-reliably-present

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!