Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a custom global from .htaccess

Is there a way to set a custom variable from within .htaccess so that every php script can then read from it ? I went googling around nothing.

Thankyou!

like image 594
kjones1876 Avatar asked Jan 08 '12 20:01

kjones1876


2 Answers

You can only set an environment variable from .htaccess:

SetEnv MYVAR whatever

And this becomes available in the $_SERVER array:

print $_SERVER["MYVAR"];

So, not exactly a global variable. But still useful for some purposes.

(The other option is declaring an auto_prepend_file to pre-define variables. But that's more a workaround then.)

like image 170
mario Avatar answered Oct 13 '22 03:10

mario


You can set environment variables in .htaccess (or http.conf):

SetEnv foo bar

and access them in PHP via

$_ENV['foo']
like image 43
konsolenfreddy Avatar answered Oct 13 '22 05:10

konsolenfreddy