Differentiate from CLI & browser

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Differentiate from CLI & browser

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Differentiate from CLI & browser

Post by Christopher »

Maybe you should check something like $_SERVER["SERVER_SOFTWARE"] or $_SERVER["SERVER_PROTOCOL"] instead.
(#10850)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Differentiate from CLI & browser

Post by John Cartwright »

Post Reply