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

$_SERVER["SCRIPT_URL"] present in my local environment (PHP 5.4.24 on Apache 2.2.26), but I read that this variable is not always present, although I could not find it exactly when it is and when it is not.

I would like to know what is required to reliably feed this variable.

+8
php compatibility
source share
2 answers

It is available only when mod_rewrite is enabled:

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

+5
source share

This variable is highly dependent on the server configuration.

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

 fastcgi_param SCRIPT_NAME $fastcgi_script_name; 

There is a similar configuration for scgi.

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

+3
source share

All Articles