Created
July 18, 2019 18:23
-
-
Save mladoux/ac02d9db5a2d2f79ffdb4d9d02b3c8f3 to your computer and use it in GitHub Desktop.
Check if PHP is being called via command line or web browser.
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 | |
function CliCheck() | |
{ | |
if (defined('STDIN')) return true; | |
if (php_sap_name() === 'cli') return true; | |
if (array_key_exists('SHELL', $_ENV)) return true; | |
if ( | |
empty($_SERVER['REMOTE_ADDR']) && | |
! isset($_SERVER['HTTP_USER_AGENT']) && | |
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