Declaring global variable with php.ini

后端 未结 8 1897
死守一世寂寞
死守一世寂寞 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 21:47

    The accepted answere also worked for me, with one change.

    I didn't test this on earlier versions, but in my environment (php 5.4.22) this doesn't show up in $_ENV, but rather in $_SERVER.

    In my .htacess file:

    SetEnv PRODUCTION_SERVER 0.  
    

    My php code:

    $production="PRODUCTION";
    if (!isset($_SERVER['PRODUCTION_SERVER']) || $_SERVER['PRODUCTION_SERVER'] != 1){
        $production="DEVELOPMENT";
    }
    

提交回复
热议问题