24

Is it possible using .htaccess or other apache powers to set a custom server value in the php array $_SERVER.

for example

if($_SERVER['is_special']) {
    echo "Yeah for us!";
} else {
    echo "No you fool!";
}

I realize I ask a lot of questions that the answer is no so feel free to say so.

1 Answer 1

42

Try the SetEnv directive:

SetEnv is_special foobar
Sign up to request clarification or add additional context in comments.

7 Comments

There it is! 'is_special' => string 'foobar' (length=6)
Note that you need mod_env to do this.
Try and avoid polluting the $_SERVER variable. I would recommend creating some sort of Registry class if you want to store global data.
Of course you can write on $_SERVER variable, it's recommended for server specified configuration (such as API key etc... Browser type detected, country detection etc...)
So it is not possible with just php code to randomly create a $_SERVER variable and assign a value for it.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.