Created
April 26, 2024 21:10
-
-
Save Bugfighter/db4ea307c3a54d2bad9da31eaad7ee0e to your computer and use it in GitHub Desktop.
Check for CLI script call.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This function checks on various environments for script call via CLI. | |
**/ | |
function is_cli() | |
{ | |
if ( defined('STDIN') ) | |
{ | |
return true; | |
} | |
if ( php_sapi_name() === 'cli' ) | |
{ | |
return true; | |
} | |
if ( array_key_exists('SHELL', $_ENV) ) { | |
return true; | |
} | |
if ( empty($_SERVER['REMOTE_ADDR']) and !isset($_SERVER['HTTP_USER_AGENT']) and count($_SERVER['argv']) > 0) | |
{ | |
return true; | |
} | |
if ( !array_key_exists('REQUEST_METHOD', $_SERVER) ) | |
{ | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment