PHP: it is possible to set constants in php.ini file by default

I want to have a constant (string) available for all PHP scripts on the server.

According to http://php.net/manual/en/function.parse-ini-file.php it is quite simple if you parse an additional .ini file, however I do not want to parse the extra file, I want to set the constant in the global php.ini without having to parse anything in scripts. (Actually, the whole point is because I need a constant to find material to include / parse / etc: When I know where this extra .ini file will be, I don't need it anymore!)

Just coming up with a new constant in php.ini and then trying to access it using ini_get () doesn't work, is there any other way?

I compile Apache and PHP myself, so I could also set the constant at compile time and / or use Apache constants if necessary.

+5
source share
3 answers

You can use a PHP auto_prepend_filescript in your PHP file to do this, since it will be launched before any of your users have -land scripts:

Specifies the name of a file that is automatically parsed before the main file. The file is included as if it were called with a function request, so include_path is used.

So you can add the ini line, for example:

auto_prepend_file="/home/user/script.php"

In / home / user / script.php:

define('CONSTANT_NAME', 'your nice value here');

Now in your PHP scripts you can access CONSTANT_NAMEfrom anywhere you like, as it is available in all PHP scripts.

, mod_rewrite, PHP- . .

+7

, , , , - $_ SERVER, ' DOCUMENT_ROOT".

0

Simple. xxx.php, include_path php.ini. , , , , .

0
source

All Articles