Page 1 of 1

Differentiate from CLI & browser

Posted: Sat Mar 08, 2008 2:18 am
by anjanesh
Hi

Whenever I want to differentiate from a script running in command-line mode from the browser, I do this

Code: Select all

if (isset($_SERVER['argc'])) # Script being run in Command line mode
 {
        // 
 }
else
 {
        // 
 }
 
if ($_SERVER['HTTP_HOST'] == "localhost") # my PC
 {
        // 
 }
else # Server
 {
        // 
 }
Its worked all this time. But theres one server powered by DirectAdmin, that shows different data

Code: Select all

Array
(
    [UNIQUE_ID] => S0ZwZtBzJT4AACXaB2UABAAP
    [HTTP_HOST] => mydomain.com
    [SERVER_NAME] => mydomain.com
    [argv] => Array
        (
        )
 
    [argc] => 0
)
1. UNIQUE_ID which I've never come across till date
2. Dont argc & argv get set only when run in CLI ?

Is the configuration custom-set ?

Linux | Apache 2.2.6 | PHP 5.2.5

Re: Differentiate from CLI & browser

Posted: Sat Mar 08, 2008 12:11 pm
by Christopher
Maybe you should check something like $_SERVER["SERVER_SOFTWARE"] or $_SERVER["SERVER_PROTOCOL"] instead.

Re: Differentiate from CLI & browser

Posted: Sat Mar 08, 2008 4:48 pm
by John Cartwright