Thanks for the idea. I have just resurrected and had another play with my 
'testbench.php', running it from both
IE/Apache and in a DOS box.

It includes the following code:
-----
echo "<br>".sizeof($argv)."~Array of Args passed to script=";
while ( $element = each( $argv ) )
{echo "<br>"; echo $element[ "key" ]; echo " = "; echo $element[ "value" ]; }
echo "<br><hr>\n";
echo "<br>".sizeof($argc)."~Cmd line params passed to script=$argc";
echo "<br><hr>\n";
-----

In the browser it responds with:
-----

0~Array of Args passed to script=

--------------------------------------------------------------------------------

1~Cmd line params passed to script=0

--------------------------------------------------------------------------------
-----

In the DOS box it produces:
-----
<br>1~Array of Args passed to script=<br>0 = c:\data\webs\brucedev\testbench.php
<br><hr>
<br>1~Cmd line params passed to script=1<br><hr>
-----

Which is a vaguely fascinating difference, but sadly, not one that adequately 
distinguishes between different
execution environments.

I'm most intrigued that my first expectation proved to be incorrect:
-----
print "check if running as CGI module: ";
if ($PHP_CGI) {print "yes";} else {print "no";}
and
$sapi_type = php_sapi_name();
if ($sapi_type == "cgi")
  print "You are using CGI PHP\n";
else
  print "You are using ".$sapi_type."PHP\n";
-----

produces the following results in both 'environments':
-----
check if running as CGI module: no~
and
You are using CGI PHP ~
-----

My script goes on and on, trying to work through as much of the PHPINFO() output as I 
can find the means/the
manual descriptions to generate. There are substantial differences in output, eg no 
Apache information is
presented to the DOS box. So the number of, ie sizeof($HTTP_ENV_VARS) also differs 
markedly.

The $GLOBALS[SERVER_ADDR] suggestion intrigued me, because it returns an IP address 
when a server is involved
(haven't looked this up, I assume it's the IP of the Apache server?) but when running 
in the DOS box there is no
server so it returns '' (empty string) or quite possibly ( !is_set() ).

Not being at all experienced in dealing with environment variables, I was hoping for 
further
clarification/inspiration.

=dn



> may be
>
> $argv
> Array of arguments passed to the script. When the script is run on the
> command line, this gives C-style access to the command line parameters. When
> called via the GET method, this will contain the query string.
>
> $argc
>
> Contains the number of command line parameters passed to the script (if run
> on the command line).
>
> In case you have any parameter
>
>
>
> hope this helps... and this should work on windows too.
>
> ----- Original Message -----
> From: "DL Neil" <[EMAIL PROTECTED]>
> To: "Mark" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>;
> <[EMAIL PROTECTED]>
> Sent: Friday, October 26, 2001 6:12 PM
> Subject: Re: [PHP] how to recognize local or server execution?
>
>
> > Mark,
> > Backing John's question up by one iteration: is there a PHP environment
> variable which can be used to
> > distinguish between code being run from the command line and code being
> run in a browser?
> > - and the Million dollar question, sorry make that the M$ question: will
> it also work under Windows?
> > Please advise,
> > =dn
> >
> >
> > On Fri, 26 Oct 2001 17:18:37 -0400, John A. Grant wrote:
> > >I have an xxx.php page that runs on my Unix server.  I also
> > >run php.exe on my NT box to generate the corresponding
> > >xxx.html file like this:
> > >  c:\> php -q xxx.php > xxx.html
> > >
> > >The xxx.php file contains stuff like this:
> > >  print "hello\n";
> > >
> > >That means stdout from the server and the xxx.html file
> > >both contain \n.  I would like the xxx.html file to contain
> > >\r\n so it can be viewed/edited with notepad. Yes,
> > >notepad and \r\n both suck, but that's another story...
> > >
> > >So I guess I would like my code to look like this:
> > >  if(running php.exe on my NT box){
> >
> > try:
> > if (strstr(php_uname(), "Windows")) {
> >
> > >    $delimiter="\r\n";
> > >  }else{
> > >    $delimiter="\n";
> > >  }
> > >
> > >and then my code looks like:
> > >  print "hello$delimiter";
> > >
> > >How can I do this?
> > >
> > >--
> > >John A. Grant  * I speak only for myself *  (remove 'z' to reply)
> > >Radiation Geophysics, Geological Survey of Canada, Ottawa
> > >If you followup, please do NOT e-mail me a copy: I will read it here
> > >
> > >
> > >
> > >
> >
> >
> > --
> > Mark, [EMAIL PROTECTED] on 10/26/2001
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to