is_safe_mode function for PHP

Posted in Programming  
E-Mail This Post/Page   

The following function will return TRUE if the server is running PHP in safe mode. It uses the function ini_get, which may be disabled. If ini_get is disabled then the function also returns TRUE since the assumption that any server disabling functions would probably also be running in safe mode.

PHP:
  1. function is_safe_mode()
  2. /*    Returns true if PHP is in safe_mode.  Defaults to 'true' because
  3. this will use ini_get which may be disabled.  If ini_get is disabled
  4. then we are probably in safe_mode    */
  5. {
  6. $retval = true;
  7.  
  8. if (function_exists('ini_get'))
  9. {
  10. if (ini_get('safe_mode')==true)
  11. {
  12. $retval = true;
  13. }
  14. else
  15. {
  16. $retval = false;
  17. }
  18. }
  19. else
  20. {
  21. $retval = true;
  22. }
  23.  
  24. return $retval;
  25. }

file_get_contents function for PHP 4
Benchmarking PHP: Inserting text with include(), require(), or get_file_contents()
A routine to create GUIDs in PHP
PHP function - directory_size()
Javascript time formatting function

Leave a Comment