5

Is it possible to make a Top Level Variable in PHP? Like Defining in .htaccess or httpd.conf? To be included in each .php file?

I would love to define BasePaths and some other variables there if possible. I am currently making some init.php and including 'em on top if each file.

tika
  • 7,135
  • 3
  • 51
  • 82

2 Answers2

3

As your working with a multi entry point application, if you want to avoid including your configuration file, you can use the php's autoprepend functionality. This will automatically include a file for you without the need to do a <?php require('init.php'); ?> in each of you entry points.

And you can find a good advice here.

David Jacquel
  • 51,670
  • 6
  • 121
  • 147
0

Based on the comments above, reference and this question, I am posting this answer future references for people in community:

Setting on .htaccess:

SetEnv VAR_NAME varValue

Also, worth mentioning:

SetEnv 'VAR NAME' 'var value' #Accepts Space with Quotes

Getting them on PHP files:

getenv('VAR_NAME')

More reference on : http://php.net/manual/en/function.getenv.php

If you are looking just to prepend a file on top of all the files and define all variables there, see David Jacquel's answer. That's cool. ;)

tika
  • 7,135
  • 3
  • 51
  • 82