How to know if php script is called via require_once()?

后端 未结 11 810
旧巷少年郎
旧巷少年郎 2021-01-07 02:24

My webapp has a buch of modules. Each module has a \'main\' php script which loads submodules based on a query sent to the main module:

//file: clientes.php
         


        
11条回答
  •  悲哀的现实
    2021-01-07 03:00

    As practice of habit I have a console class built to send messages, errors, etc. to console with FirePHP. Inside the Console class write() method I have a check to see if a $_REQUEST[debug] == 1, that way I'm not exposing errors to users if something pops up on production and they would have to know what the request variable is to access the debug information.

    At the top of every file I add:

    Console::debug('fileName.php is loaded.');
    

    here is a snippit from it to give you the right idea:

    class Console{
    
      public static function write($msg,$msg_type='info',$msg_label=''){
        if(isset($_REQUEST['debug']) && $_REQUEST['debug'] == 'PANCAKE!'){
          ob_start();
          switch($msg_type){
            case 'info':
              FB::info($msg, $msg_label);
              break;
            case 'debug':
              FB::info($msg, 'DEBUG')
              break;
              ...
          }
        }
      }
    
      public static function debug($msg){
        Console::write($msg, '');
      }
    }
    

提交回复
热议问题