Posted by Bret Hughes on 01/19/05 19:08
On Wed, 2005-01-19 at 07:47, Al wrote:
> I'm working on a script that can be initiated by a cronjob or from a browser.
>
> I want the script to act differently depending on which one called it.
>
> --
I do not know what the definitive answer is but there are a bunch of
environment differences. Here is one taken from
http://us2.php.net/features.commandline
[bhughes@sonecdm elevatetest]$ cat testbrowser.php
<?php
if ($_SERVER['SERVER_PORT']) { echo "SERVER MODE\n"; }
else { echo "CLI MODE\n"; }
?>
results from wget:
[bhughes@sonecdm elevatetest]$ wget -q --output-document=-
https://localhost/elevatetest/testbrowser.php
SERVER MODE
[bhughes@sonecdm elevatetest]$
results from cli
[bhughes@sonecdm elevatetest]$ php testbrowser.php
Content-type: text/html
X-Powered-By: PHP/4.3.6
CLI MODE
[bhughes@sonecdm elevatetest]$
mozilla returns
SERVER MODE
HTH
Bret
[Back to original message]
|