phpscopeconstantsmagic-string

Defining your own magic constants in php?


Is there anyway in php, by which we can define our own magic constants, which value could vary throughout the program and how to define variables with the SUPER GLOBAL SCOPE.


Solution

  • Just add the variable as an Apache environment variable:

    SetEnv foo bar
    

    You could set that in httpd.conf, apache2.conf, or .htaccess.PHP should then be able to access it via one or more of the following methods:

    $_SERVER['foo']
    $_ENV['foo']
    getenv('foo')