how to tell cmd line vs. browser

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven Stern

    how to tell cmd line vs. browser

    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?
  • Pedro Graca

    #2
    Re: how to tell cmd line vs. browser

    Steven Stern wrote:[color=blue]
    > 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?[/color]

    Maybe php_sapi_name() can help you.

    Returns the type of interface between web server and PHP


    --
    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 :

    Comment

    • Martin Geisler

      #3
      Re: how to tell cmd line vs. browser

      Steven Stern <sdsternNOSPAMH ERE@NOSPAMHEREm indspring.com> writes:
      [color=blue]
      > 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?[/color]

      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):



      --
      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

      Comment

      • Steven Stern

        #4
        Re: how to tell cmd line vs. browser

        On 22 May 2004 19:43:25 GMT (more or less), Pedro Graca <hexkid@hotpop. com>
        wrote:
        [color=blue]
        >Steven Stern wrote:[color=green]
        >> 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?[/color]
        >
        >Maybe php_sapi_name() can help you.
        >
        >http://www.php.net/php_sapi_name[/color]

        That'll do it. Thanks.

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

        Comment

        Working...