Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Variable to $_SERVER array via php.ini

Tags:

php

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

like image 221
TSS Avatar asked Jul 13 '11 08:07

TSS


People also ask

What is $_ server [' Php_self ']?

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.

What is $_ server [' Request_uri ']?

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

Is $_ server an array?

$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server.

What is the purpose of $_ server variable in PHP?

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


3 Answers

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'].

like image 177
cochet Avatar answered Oct 12 '22 00:10

cochet


If you're using Apache, try the SetEnv module.

(you can see more here: Declaring global variable with php.ini)

like image 28
jlb Avatar answered Oct 12 '22 01:10

jlb


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.

like image 23
timdev Avatar answered Oct 12 '22 00:10

timdev