Declaring global variable with php.ini

后端 未结 8 1876
死守一世寂寞
死守一世寂寞 2020-12-03 21:12

Is it possible to keep variables in php.ini file. Like that we do with the web.config in .net. I like to keep a flag type variable in the php.ini and use it to different pro

8条回答
  •  眼角桃花
    2020-12-03 22:04

    Complementing @Ascherer answer, use get_cfg_var() to save custom variables in custom php.ini (variable created by you, not an official PHP ini directive). For example:

    In php.ini: custom_variable = "abcde"
    In any php script: get_cfg_var('custom_variable') returns abcde

    I use this in in a small project in local dev. As I run the local server via php -S localhost:8000 -c php.ini (not running an Apache server locally), it's a good option to call some configuration constants. In production, these constants are set in .htaccess.

提交回复
热议问题