I need to add a variable to the $_SERVER array in a php script. Is there a possibility to do this via the php.ini file? I want to add the variable for all scripts on the webserver, so it's quite inconvenient to add it in each script.
Thanks, TSS
Description. $_SERVER['PHP_SELF'] Returns the filename of the currently executing script. $_SERVER['GATEWAY_INTERFACE'] Returns the version of the Common Gateway Interface (CGI) the server is using.
$_SERVER['REQUEST_URI'] contains the URI of the current page. So if the full path of a page is https://www.w3resource.com/html/html-tutorials.php, $_SERVER['REQUEST_URI'] would contain /html/html-tutorials. php. Following php code used $_SERVER['REQUEST_URI'] variable.
$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server.
$_SERVER is a superglobal that holds information regarding HTTP headers, path and script location etc. All the server and execution environment related information is available in this associative array. Most of the entries in this array are populated by web server.
You can set it in your .htaccess or in the apache configuration
<VirtualHost *:80>
...
SetEnv PARAM "VALUE"
...
</VirtualHost>
It will be added to the variable $_SERVER['PARAM'].
If you're using Apache, try the SetEnv module.
(you can see more here: Declaring global variable with php.ini)
I can't think of a way to add things to $_SERVER via php.ini (which doesn't mean there's no way to do it).
However, you could add things to $_ENV, server-wide, using SetEnv in httpd.conf (assuming apache, here). There are likely methods for doing this with other web servers, but I'm not sure what they are.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With