Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is PHP's $_SERVER superglobal guaranteed to be writeable?

My PHP scripts are able to write to the superglobal array $_SERVER.

Whilst messing with $_SERVER is pretty obviously a bad idea in almost all cases, there may be situations where it could be useful as a short-term band-aid or for some kinds of testing. Can I rely on it being writeable by scripts, or is this something that might be:

  • different for different servers or PHP versions?
  • controllable by some ini setting?

The PHP docs don’t appear to specify whether S_SERVER should be, or might be, read-only. They do imply that it’s just a variable, and therefore writeable like any other variable. However, since it’s a rather special variable, it seems reasonable to ask the question. It’s very easy to show $_SERVER being modified on a real PHP web page:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<?php
$uri = $_SERVER['REQUEST_URI'];
$_SERVER['REQUEST_URI'] = "test-value";

echo '<pre>
Before: "'.$uri.'"
After : "'.$_SERVER['REQUEST_URI'].'"
</pre>';

die();

>Solution :

All superglobals are writable.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading