Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Apache is adding those REDIRECT_ prefixes so that scripts can better handle what has happened. For my application I have written a function to deal with this. In my case it's a method on a class, but you can easily turn it into a global function.</p> <pre><code>class MyClass { /** @var integer How deep the redirect layers of Apache go. -1 means not set. */ private $redirectLevel = -1; /** * Get an environment variable with all the REDIRECT_ prefixes stripped off */ private function getEnv($var) { // Find out how deep the redirect goes if ($this-&gt;redirectLevel == -1) { reset($_SERVER); $key = key($_SERVER); $this-&gt;redirectLevel = substr_count($key, 'REDIRECT_'); } $result = ''; $prefix = ''; for ($i = 0; $i &lt; $this-&gt;redirectLevel + 1; $i++) { if (isset($_SERVER[$prefix . $var])) { $result = $_SERVER[$prefix . $var]; } $prefix .= 'REDIRECT_'; } return $result; } } </code></pre> <p><strong>EDIT:</strong> The above function returns the contents of the variable that has the most REDIRECT_ prefixes, which is usually what you want. If Apache would not prefix the variables then that is what you'd get. The contents of the variables can change depending on the number of prefixes. After all, Apache adds the prefix so it does not overwrite the old value.</p> <p>For example, on my site I use mod_ssl to do client authentication with client SSL certificates. The certificate subject (containing the user's e-mail address) is stored in the SSL_CLIENT_S_DN variable. With Apache prefixing, this will come out as:</p> <pre><code>$_SERVER['REDIRECT_REDIRECT_SSL_CLIENT_S_DN'] // string containing the subject $_SERVER['REDIRECT_SSL_CLIENT_S_DN'] // exists, but empty // $_SERVER['SSL_CLIENT_S_DN'] does not exist </code></pre> <p>The getEnv() function I wrote above will return the top one.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload