Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set custom $_SERVER variables from client in PHP

Tags:

php

According to this post: Which $_SERVER variables are safe? and another I've seen, a client seems to be able to set custom $_SERVER variables. For example: $_SERVER['HTTP_EXAMPLE']

How would a client actually set a value to $_SERVER['HTTP_EXAMPLE']?

like image 562
Grumpy Avatar asked May 01 '15 13:05

Grumpy


People also ask

What is $_ SERVER [' Script_name ']?

$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here.

What is $_ SERVER [' PHP_SELF ']?

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

What is $_ SERVER Document_root?

$_SERVER['DOCUMENT_ROOT'] returns. The document root directory under which the current script is executing, as defined in the server's configuration file.


1 Answers

If you have access to the Apache config file, you can do it using mod_env

SetEnv HTTP_EXAMPLE http_example

Then you can access that variable

echo $_SERVER["HTTP_EXAMPLE"]; //outputs http_example
like image 63
Alex Avatar answered Oct 06 '22 20:10

Alex