By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,018 Members | 878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,018 IT Pros & Developers. It's quick & easy.

how to tell cmd line vs. browser

P: n/a
I have a script that will be run as a cron task every night but occasionally
will run when request by the browser. When run by the browser, I want it to
output results to the screen.

What's an easy way to tell how my .php file was invoked?
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Steven Stern wrote:
I have a script that will be run as a cron task every night but occasionally
will run when request by the browser. When run by the browser, I want it to
output results to the screen.

What's an easy way to tell how my .php file was invoked?


Maybe php_sapi_name() can help you.

http://www.php.net/php_sapi_name

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2

P: n/a
Steven Stern <sd***************@NOSPAMHEREmindspring.com> writes:
I have a script that will be run as a cron task every night but
occasionally will run when request by the browser. When run by the
browser, I want it to output results to the screen.

What's an easy way to tell how my .php file was invoked?


You can use the php_sapi_name() function and see if it return 'cgi',
assuming that you know for sure that PHP wont run as CGI on the
webserver (this is true with most installations where PHP runs as a
module in the webserver):

http://php.net/manual/en/function.php-sapi-name.php

--
Martin Geisler My GnuPG Key: 0xF7F6B57B

PHP EXIF Library | PhpWeather | PhpShell
http://pel.sf.net/ | http://phpweather.net/ | http://gimpster.com/
Read/write EXIF data | Show current weather | A shell in a browser
Jul 17 '05 #3

P: n/a
On 22 May 2004 19:43:25 GMT (more or less), Pedro Graca <he****@hotpop.com>
wrote:
Steven Stern wrote:
I have a script that will be run as a cron task every night but occasionally
will run when request by the browser. When run by the browser, I want it to
output results to the screen.

What's an easy way to tell how my .php file was invoked?


Maybe php_sapi_name() can help you.

http://www.php.net/php_sapi_name


That'll do it. Thanks.

When run from a browser, it returns "apache". When run from the command
line, it returns "cgi".

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.