Script running under Command Prompt or Browser or some other

Script running under Command Prompt or Browser or some other

am 28.11.2007 06:34:52 von Ojas

Hi!,

I just out of curiosity want to know how top detect the client side
application under which the script is getting run. I mean to ask the
how to know whether the script is running under Command Prompt or
Browser or some other application?

Ojas.

Re: Script running under Command Prompt or Browser or some other

am 28.11.2007 06:51:26 von nc

On Nov 27, 9:34 pm, Ojas wrote:
>
> I just out of curiosity want to know how top detect
> the client side application under which the script
> is getting run. I mean to ask the how to know whether
> the script is running under Command Prompt or Browser
> or some other application?

This is not exactly possible. What is possible is knowing which PHP
interpreter (server module, CGI, command line, etc.) is processing the
current script:

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

As to the client-side application requesting the script, the client is
under no obligation to identify itself. If it does identify itself
(by sending a "User-Agent:" request header), data sent in that header
are made available to the script as $_SERVER["HTTP_USER_AGENT"].

Cheers,
NC

Re: Script running under Command Prompt or Browser or some other

am 28.11.2007 16:29:47 von Kailash Nadh

On Nov 28, 5:34 am, Ojas wrote:
> Hi!,
>
> I just out of curiosity want to know how top detect the client side
> application under which the script is getting run. I mean to ask the
> how to know whether the script is running under Command Prompt or
> Browser or some other application?
>
> Ojas.

Yep, when a php script is run from the commandline, the two variables
$argc and $argv (commandline arguments) are registered.
They might be empty, but they still would be registered when being run
from the commandline (and not when not in the commandline)
http://uk.php.net/features.commandline

--
Kailash Nadh | http://kailashnadh.name

Re: Script running under Command Prompt or Browser or some other application?

am 28.11.2007 19:26:28 von Jerry Stuckle

Kailash Nadh wrote:
> On Nov 28, 5:34 am, Ojas wrote:
>> Hi!,
>>
>> I just out of curiosity want to know how top detect the client side
>> application under which the script is getting run. I mean to ask the
>> how to know whether the script is running under Command Prompt or
>> Browser or some other application?
>>
>> Ojas.
>
> Yep, when a php script is run from the commandline, the two variables
> $argc and $argv (commandline arguments) are registered.
> They might be empty, but they still would be registered when being run
> from the commandline (and not when not in the commandline)
> http://uk.php.net/features.commandline
>
> --
> Kailash Nadh | http://kailashnadh.name
>

But that's server side. He asked about client side. And the answer is
there is no good way.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Script running under Command Prompt or Browser or some other

am 29.11.2007 11:53:23 von Ojas

On Nov 28, 11:26 pm, Jerry Stuckle wrote:
> Kailash Nadh wrote:
> > On Nov 28, 5:34 am, Ojas wrote:
> >> Hi!,
>
> >> I just out of curiosity want to know how top detect the client side
> >> application under which the script is getting run. I mean to ask the
> >> how to know whether the script is running under Command Prompt or
> >> Browser or some other application?
>
> >> Ojas.
>
> > Yep, when a php script is run from the commandline, the two variables
> > $argc and $argv (commandline arguments) are registered.
> > They might be empty, but they still would be registered when being run
> > from the commandline (and not when not in the commandline)
> >http://uk.php.net/features.commandline
>
> > --
> > Kailash Nadh |http://kailashnadh.name
>
> But that's server side. He asked about client side. And the answer is
> there is no good way.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

Thanks to all of you for replying but i still think there should be a
way to know that. Actually someone may have to implement a check on
the basis of that. Unavailability of the functionality can break the
logic!!

Ojas

Re: Script running under Command Prompt or Browser or some other

am 29.11.2007 12:02:25 von Captain Paralytic

On 28 Nov, 05:34, Ojas wrote:
> Hi!,
>
> I just out of curiosity want to know how top detect the client side
> application under which the script is getting run. I mean to ask the
> how to know whether the script is running under Command Prompt or
> Browser or some other application?
>
> Ojas.

A php script does not run under a browser. A browser (or other client
site application) may make a call to a web server. A web server will
go to serve the file and the web sever's configration may tell it that
the file might contain php script and that it should therefore be
presented to the php interpreter. The web server may pass on some
details of the client, but it has no way to verify then as all the web
server receives is an http request.

I love you comment "Thanks to all of you for replying but i still
think there should be a way to know that." Maybe you should start a
petition!

Re: Script running under Command Prompt or Browser or some other

am 29.11.2007 12:51:33 von brunormbarros

>Thanks to all of you for replying but i still think there should be a
>way to know that. Actually someone may have to implement a check on
>the basis of that. Unavailability of the functionality can break the
>logic!!

Not wanting to be pessimistic or contraditory, I think what he meant
was how to find a way to know which application executed the request.

If you open a request to a PHP script from another PHP script, there
will be a PHP user agent (dont know its name from my head), whilst on
a browser, the browsers details will be sent. Lets just say with PHP,
you can check if its command line by checking IF $argc and $argv
exist, to check if its a browser, compare it to a list of known
browsers (PHP.net has one huge file for that) and if its not run on
command line, if its not run on a known browser, then it can only be
another application.

Is that what you were looking to know, Ojas?

Re: Script running under Command Prompt or Browser or some other application?

am 29.11.2007 13:46:02 von Jerry Stuckle

Ojas wrote:
> On Nov 28, 11:26 pm, Jerry Stuckle wrote:
>> Kailash Nadh wrote:
>>> On Nov 28, 5:34 am, Ojas wrote:
>>>> Hi!,
>>>> I just out of curiosity want to know how top detect the client side
>>>> application under which the script is getting run. I mean to ask the
>>>> how to know whether the script is running under Command Prompt or
>>>> Browser or some other application?
>>>> Ojas.
>>> Yep, when a php script is run from the commandline, the two variables
>>> $argc and $argv (commandline arguments) are registered.
>>> They might be empty, but they still would be registered when being run
>>> from the commandline (and not when not in the commandline)
>>> http://uk.php.net/features.commandline
>>> --
>>> Kailash Nadh |http://kailashnadh.name
>> But that's server side. He asked about client side. And the answer is
>> there is no good way.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> Thanks to all of you for replying but i still think there should be a
> way to know that. Actually someone may have to implement a check on
> the basis of that. Unavailability of the functionality can break the
> logic!!
>
> Ojas
>

Sorry - knowing what's running on the client side depends on the client
telling you. And that's not reliable.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Script running under Command Prompt or Browser or some other

am 29.11.2007 13:52:42 von Captain Paralytic

On 29 Nov, 11:51, Bruno Rafael Moreira de Barros
wrote:
> >Thanks to all of you for replying but i still think there should be a
> >way to know that. Actually someone may have to implement a check on
> >the basis of that. Unavailability of the functionality can break the
> >logic!!
>
> Not wanting to be pessimistic or contraditory, I think what he meant
> was how to find a way to know which application executed the request.
>
> If you open a request to a PHP script from another PHP script, there
> will be a PHP user agent (dont know its name from my head), whilst on
> a browser, the browsers details will be sent. Lets just say with PHP,
> you can check if its command line by checking IF $argc and $argv
> exist, to check if its a browser, compare it to a list of known
> browsers (PHP.net has one huge file for that) and if its not run on
> command line, if its not run on a known browser, then it can only be
> another application.
>
> Is that what you were looking to know, Ojas?

"if its not run on a known browser" and I say again, a browser does
not run a php script. A script will never be run on a browser.

Re: Script running under Command Prompt or Browser or some other

am 05.12.2007 10:18:36 von Ojas

On Nov 29, 4:51 pm, Bruno Rafael Moreira de Barros
wrote:
> >Thanks to all of you for replying but i still think there should be a
> >way to know that. Actually someone may have to implement a check on
> >the basis of that. Unavailability of the functionality can break the
> >logic!!
>
> Not wanting to be pessimistic or contraditory, I think what he meant
> was how to find a way to know which application executed the request.
>
> If you open a request to a PHP script from another PHP script, there
> will be a PHP user agent (dont know its name from my head), whilst on
> a browser, the browsers details will be sent. Lets just say with PHP,
> you can check if its command line by checking IF $argc and $argv
> exist, to check if its a browser, compare it to a list of known
> browsers (PHP.net has one huge file for that) and if its not run on
> command line, if its not run on a known browser, then it can only be
> another application.
>
> Is that what you were looking to know, Ojas?

You are right Bruno Rafael. I am willing to know the type of
application sending request to the server to run a PHP script (i think
it should be clear to all other ones that i am not asking for how
script will run on client side.)

As you have specified, if the request has been sent through command
line, $argc & $arv will exists whether having any values or not but
since we can access these values from $_SERVER (or $_ENV not sure
about it) which itself is an array, not set $_SERVER['argc'] is
equivalent to null $_SERVER['argc'], accessing the $_SERVER['argc']
will result to null values in both cases, then how one can distinguish
these cases?

Ojas.

Re: Script running under Command Prompt or Browser or some other application?

am 05.12.2007 12:56:22 von Jerry Stuckle

Ojas wrote:
> On Nov 29, 4:51 pm, Bruno Rafael Moreira de Barros
> wrote:
>>> Thanks to all of you for replying but i still think there should be a
>>> way to know that. Actually someone may have to implement a check on
>>> the basis of that. Unavailability of the functionality can break the
>>> logic!!
>> Not wanting to be pessimistic or contraditory, I think what he meant
>> was how to find a way to know which application executed the request.
>>
>> If you open a request to a PHP script from another PHP script, there
>> will be a PHP user agent (dont know its name from my head), whilst on
>> a browser, the browsers details will be sent. Lets just say with PHP,
>> you can check if its command line by checking IF $argc and $argv
>> exist, to check if its a browser, compare it to a list of known
>> browsers (PHP.net has one huge file for that) and if its not run on
>> command line, if its not run on a known browser, then it can only be
>> another application.
>>
>> Is that what you were looking to know, Ojas?
>
> You are right Bruno Rafael. I am willing to know the type of
> application sending request to the server to run a PHP script (i think
> it should be clear to all other ones that i am not asking for how
> script will run on client side.)
>

PHP scripts do not run on the client side.

> As you have specified, if the request has been sent through command
> line, $argc & $arv will exists whether having any values or not but
> since we can access these values from $_SERVER (or $_ENV not sure
> about it) which itself is an array, not set $_SERVER['argc'] is
> equivalent to null $_SERVER['argc'], accessing the $_SERVER['argc']
> will result to null values in both cases, then how one can distinguish
> these cases?
>
> Ojas.
>

As he said - if it is from the command line, $argc and $argv will exist,
as will $_SERVER['argc'] and $_SERVER['argv']. But you shouldn't be
even trying to access them unless you know they exist - they will give a
NOTICE if you have errors enabled and displayed (which you should in a
development environment).

Check out isset() and array_key_exists(), for instance.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Script running under Command Prompt or Browser or some other application?

am 05.12.2007 12:56:22 von Jerry Stuckle

Ojas wrote:
> On Nov 29, 4:51 pm, Bruno Rafael Moreira de Barros
> wrote:
>>> Thanks to all of you for replying but i still think there should be a
>>> way to know that. Actually someone may have to implement a check on
>>> the basis of that. Unavailability of the functionality can break the
>>> logic!!
>> Not wanting to be pessimistic or contraditory, I think what he meant
>> was how to find a way to know which application executed the request.
>>
>> If you open a request to a PHP script from another PHP script, there
>> will be a PHP user agent (dont know its name from my head), whilst on
>> a browser, the browsers details will be sent. Lets just say with PHP,
>> you can check if its command line by checking IF $argc and $argv
>> exist, to check if its a browser, compare it to a list of known
>> browsers (PHP.net has one huge file for that) and if its not run on
>> command line, if its not run on a known browser, then it can only be
>> another application.
>>
>> Is that what you were looking to know, Ojas?
>
> You are right Bruno Rafael. I am willing to know the type of
> application sending request to the server to run a PHP script (i think
> it should be clear to all other ones that i am not asking for how
> script will run on client side.)
>

PHP scripts do not run on the client side.

> As you have specified, if the request has been sent through command
> line, $argc & $arv will exists whether having any values or not but
> since we can access these values from $_SERVER (or $_ENV not sure
> about it) which itself is an array, not set $_SERVER['argc'] is
> equivalent to null $_SERVER['argc'], accessing the $_SERVER['argc']
> will result to null values in both cases, then how one can distinguish
> these cases?
>
> Ojas.
>

As he said - if it is from the command line, $argc and $argv will exist,
as will $_SERVER['argc'] and $_SERVER['argv']. But you shouldn't be
even trying to access them unless you know they exist - they will give a
NOTICE if you have errors enabled and displayed (which you should in a
development environment).

Check out isset() and array_key_exists(), for instance.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Script running under Command Prompt or Browser or some other application?

am 05.12.2007 16:27:18 von AnrDaemon

Greetings, Jerry Stuckle.
In reply to Your message dated Wednesday, December 5, 2007, 14:56:22,

> As he said - if it is from the command line, $argc and $argv will exist,
> as will $_SERVER['argc'] and $_SERVER['argv'].

Not if it is started using PHP-CGI and argc/argv vars disabled in
configuration.


--
Sincerely Yours, AnrDaemon

Re: Script running under Command Prompt or Browser or some other application?

am 05.12.2007 16:27:18 von AnrDaemon

Greetings, Jerry Stuckle.
In reply to Your message dated Wednesday, December 5, 2007, 14:56:22,

> As he said - if it is from the command line, $argc and $argv will exist,
> as will $_SERVER['argc'] and $_SERVER['argv'].

Not if it is started using PHP-CGI and argc/argv vars disabled in
configuration.


--
Sincerely Yours, AnrDaemon

Re: Script running under Command Prompt or Browser or some other application?

am 05.12.2007 21:24:58 von Jerry Stuckle

AnrDaemon wrote:
> Greetings, Jerry Stuckle.
> In reply to Your message dated Wednesday, December 5, 2007, 14:56:22,
>
>> As he said - if it is from the command line, $argc and $argv will exist,
>> as will $_SERVER['argc'] and $_SERVER['argv'].
>
> Not if it is started using PHP-CGI and argc/argv vars disabled in
> configuration.
>
>

If it's using php-cgi, then it's not started from the command line, is it?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Script running under Command Prompt or Browser or some other application?

am 05.12.2007 21:24:58 von Jerry Stuckle

AnrDaemon wrote:
> Greetings, Jerry Stuckle.
> In reply to Your message dated Wednesday, December 5, 2007, 14:56:22,
>
>> As he said - if it is from the command line, $argc and $argv will exist,
>> as will $_SERVER['argc'] and $_SERVER['argv'].
>
> Not if it is started using PHP-CGI and argc/argv vars disabled in
> configuration.
>
>

If it's using php-cgi, then it's not started from the command line, is it?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Script running under Command Prompt or Browser or some other

am 06.12.2007 04:21:37 von nc

On Dec 5, 1:18 am, Ojas wrote:
>
> if the request has been sent through command line, $argc &
> $arv will exists whether having any values or not but since
> we can access these values from $_SERVER (or $_ENV not sure
> about it) which itself is an array, not set $_SERVER['argc']
> is equivalent to null $_SERVER['argc'], accessing the
> $_SERVER['argc'] will result to null values in both cases,
> then how one can distinguish these cases?

There's no need to. If the script is running from the command line, a
call to php_sapi_name() will return 'cli'.

Cheers,
NC

Re: Script running under Command Prompt or Browser or some other

am 06.12.2007 05:05:17 von Ojas

On Dec 6, 8:21 am, NC wrote:
> On Dec 5, 1:18 am, Ojas wrote:
>
>
>
> > if the request has been sent through command line, $argc &
> > $arv will exists whether having any values or not but since
> > we can access these values from $_SERVER (or $_ENV not sure
> > about it) which itself is an array, not set $_SERVER['argc']
> > is equivalent to null $_SERVER['argc'], accessing the
> > $_SERVER['argc'] will result to null values in both cases,
> > then how one can distinguish these cases?
>
> There's no need to. If the script is running from the command line, a
> call to php_sapi_name() will return 'cli'.
>
> Cheers,
> NC

Hi! all,

NC has provided a very useful point of using php_sapi_name to detect
the same. I tried to print 'PHP_SAPI' on my system and got the
following result:

Browser: apache2handler
Command Prompt: cli

I think it is of great help and we are going to have a robust
solution. Meanwhile, i would appreciate if anyone of you could share
the list of all possible php sapi (along with their possible
application from which they will be in existence).

And yes Jerry Stuckle do provided the good way of distinguish between
'not set element' and 'null element' inside the array. I was known to
it, but somehow it get slipped out of my mind.

Cheers! NC & Jerry Stuckle.

To continue the discussion, i would like to extend it a little bit
further by asking how to detect whether a request to the server has
been made directly or using sockets or using CURL from the client side
application?

Ojas

Re: Script running under Command Prompt or Browser or some other application?

am 06.12.2007 06:02:25 von Jerry Stuckle

Ojas wrote:
> On Dec 6, 8:21 am, NC wrote:
>> On Dec 5, 1:18 am, Ojas wrote:
>>
>>
>>
>>> if the request has been sent through command line, $argc &
>>> $arv will exists whether having any values or not but since
>>> we can access these values from $_SERVER (or $_ENV not sure
>>> about it) which itself is an array, not set $_SERVER['argc']
>>> is equivalent to null $_SERVER['argc'], accessing the
>>> $_SERVER['argc'] will result to null values in both cases,
>>> then how one can distinguish these cases?
>> There's no need to. If the script is running from the command line, a
>> call to php_sapi_name() will return 'cli'.
>>
>> Cheers,
>> NC
>
> Hi! all,
>
> NC has provided a very useful point of using php_sapi_name to detect
> the same. I tried to print 'PHP_SAPI' on my system and got the
> following result:
>
> Browser: apache2handler
> Command Prompt: cli
>
> I think it is of great help and we are going to have a robust
> solution. Meanwhile, i would appreciate if anyone of you could share
> the list of all possible php sapi (along with their possible
> application from which they will be in existence).
>
> And yes Jerry Stuckle do provided the good way of distinguish between
> 'not set element' and 'null element' inside the array. I was known to
> it, but somehow it get slipped out of my mind.
>
> Cheers! NC & Jerry Stuckle.
>
> To continue the discussion, i would like to extend it a little bit
> further by asking how to detect whether a request to the server has
> been made directly or using sockets or using CURL from the client side
> application?
>
> Ojas
>

No way to tell. This depends on the user agent sending information,
which is not reliable. For instance, depending on the site I'm
interfacing to in CURL, I might send some string such as "PHP-CURL", or
I might send the user agent the client is using (i.e. Firefox, IE, etc.).


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Script running under Command Prompt or Browser or some other application?

am 06.12.2007 06:02:25 von Jerry Stuckle

Ojas wrote:
> On Dec 6, 8:21 am, NC wrote:
>> On Dec 5, 1:18 am, Ojas wrote:
>>
>>
>>
>>> if the request has been sent through command line, $argc &
>>> $arv will exists whether having any values or not but since
>>> we can access these values from $_SERVER (or $_ENV not sure
>>> about it) which itself is an array, not set $_SERVER['argc']
>>> is equivalent to null $_SERVER['argc'], accessing the
>>> $_SERVER['argc'] will result to null values in both cases,
>>> then how one can distinguish these cases?
>> There's no need to. If the script is running from the command line, a
>> call to php_sapi_name() will return 'cli'.
>>
>> Cheers,
>> NC
>
> Hi! all,
>
> NC has provided a very useful point of using php_sapi_name to detect
> the same. I tried to print 'PHP_SAPI' on my system and got the
> following result:
>
> Browser: apache2handler
> Command Prompt: cli
>
> I think it is of great help and we are going to have a robust
> solution. Meanwhile, i would appreciate if anyone of you could share
> the list of all possible php sapi (along with their possible
> application from which they will be in existence).
>
> And yes Jerry Stuckle do provided the good way of distinguish between
> 'not set element' and 'null element' inside the array. I was known to
> it, but somehow it get slipped out of my mind.
>
> Cheers! NC & Jerry Stuckle.
>
> To continue the discussion, i would like to extend it a little bit
> further by asking how to detect whether a request to the server has
> been made directly or using sockets or using CURL from the client side
> application?
>
> Ojas
>

No way to tell. This depends on the user agent sending information,
which is not reliable. For instance, depending on the site I'm
interfacing to in CURL, I might send some string such as "PHP-CURL", or
I might send the user agent the client is using (i.e. Firefox, IE, etc.).


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Script running under Command Prompt or Browser or some other

am 06.12.2007 06:26:49 von Ojas

On Dec 6, 10:02 am, Jerry Stuckle wrote:
> Ojas wrote:
> > On Dec 6, 8:21 am, NC wrote:
> >> On Dec 5, 1:18 am, Ojas wrote:
>
> >>> if the request has been sent through command line, $argc &
> >>> $arv will exists whether having any values or not but since
> >>> we can access these values from $_SERVER (or $_ENV not sure
> >>> about it) which itself is an array, not set $_SERVER['argc']
> >>> is equivalent to null $_SERVER['argc'], accessing the
> >>> $_SERVER['argc'] will result to null values in both cases,
> >>> then how one can distinguish these cases?
> >> There's no need to. If the script is running from the command line, a
> >> call to php_sapi_name() will return 'cli'.
>
> >> Cheers,
> >> NC
>
> > Hi! all,
>
> > NC has provided a very useful point of using php_sapi_name to detect
> > the same. I tried to print 'PHP_SAPI' on my system and got the
> > following result:
>
> > Browser: apache2handler
> > Command Prompt: cli
>
> > I think it is of great help and we are going to have a robust
> > solution. Meanwhile, i would appreciate if anyone of you could share
> > the list of all possible php sapi (along with their possible
> >applicationfrom which they will be in existence).
>
> > And yes Jerry Stuckle do provided the good way of distinguish between
> > 'not set element' and 'null element' inside the array. I was known to
> > it, but somehow it get slipped out of my mind.
>
> > Cheers! NC & Jerry Stuckle.
>
> > To continue the discussion, i would like to extend it a little bit
> > further by asking how to detect whether a request to the server has
> > been made directly or using sockets or using CURL from the client side
> >application?
>
> > Ojas
>
> No way to tell. This depends on the user agent sending information,
> which is not reliable. For instance, depending on the site I'm
> interfacing to in CURL, I might send some string such as "PHP-CURL", or
> I might send the user agent the client is using (i.e. Firefox, IE, etc.).
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

Ok.

That's correct, but in case someone is wishing to deny the request
coming from the CURL or socket way, then what should be the procedure?

Ojas

Re: Script running under Command Prompt or Browser or some other application?

am 06.12.2007 06:46:25 von Jerry Stuckle

Ojas wrote:
> On Dec 6, 10:02 am, Jerry Stuckle wrote:
>> Ojas wrote:
>>> On Dec 6, 8:21 am, NC wrote:
>>>> On Dec 5, 1:18 am, Ojas wrote:
>>>>> if the request has been sent through command line, $argc &
>>>>> $arv will exists whether having any values or not but since
>>>>> we can access these values from $_SERVER (or $_ENV not sure
>>>>> about it) which itself is an array, not set $_SERVER['argc']
>>>>> is equivalent to null $_SERVER['argc'], accessing the
>>>>> $_SERVER['argc'] will result to null values in both cases,
>>>>> then how one can distinguish these cases?
>>>> There's no need to. If the script is running from the command line, a
>>>> call to php_sapi_name() will return 'cli'.
>>>> Cheers,
>>>> NC
>>> Hi! all,
>>> NC has provided a very useful point of using php_sapi_name to detect
>>> the same. I tried to print 'PHP_SAPI' on my system and got the
>>> following result:
>>> Browser: apache2handler
>>> Command Prompt: cli
>>> I think it is of great help and we are going to have a robust
>>> solution. Meanwhile, i would appreciate if anyone of you could share
>>> the list of all possible php sapi (along with their possible
>>> applicationfrom which they will be in existence).
>>> And yes Jerry Stuckle do provided the good way of distinguish between
>>> 'not set element' and 'null element' inside the array. I was known to
>>> it, but somehow it get slipped out of my mind.
>>> Cheers! NC & Jerry Stuckle.
>>> To continue the discussion, i would like to extend it a little bit
>>> further by asking how to detect whether a request to the server has
>>> been made directly or using sockets or using CURL from the client side
>>> application?
>>> Ojas
>> No way to tell. This depends on the user agent sending information,
>> which is not reliable. For instance, depending on the site I'm
>> interfacing to in CURL, I might send some string such as "PHP-CURL", or
>> I might send the user agent the client is using (i.e. Firefox, IE, etc.).
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> Ok.
>
> That's correct, but in case someone is wishing to deny the request
> coming from the CURL or socket way, then what should be the procedure?
>
> Ojas
>

There is none. There is no way you can tell what the client is running,
other than what the client tells you. And that is not reliable.

The real question here is - what problem are you having?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Script running under Command Prompt or Browser or some other application?

am 06.12.2007 06:46:25 von Jerry Stuckle

Ojas wrote:
> On Dec 6, 10:02 am, Jerry Stuckle wrote:
>> Ojas wrote:
>>> On Dec 6, 8:21 am, NC wrote:
>>>> On Dec 5, 1:18 am, Ojas wrote:
>>>>> if the request has been sent through command line, $argc &
>>>>> $arv will exists whether having any values or not but since
>>>>> we can access these values from $_SERVER (or $_ENV not sure
>>>>> about it) which itself is an array, not set $_SERVER['argc']
>>>>> is equivalent to null $_SERVER['argc'], accessing the
>>>>> $_SERVER['argc'] will result to null values in both cases,
>>>>> then how one can distinguish these cases?
>>>> There's no need to. If the script is running from the command line, a
>>>> call to php_sapi_name() will return 'cli'.
>>>> Cheers,
>>>> NC
>>> Hi! all,
>>> NC has provided a very useful point of using php_sapi_name to detect
>>> the same. I tried to print 'PHP_SAPI' on my system and got the
>>> following result:
>>> Browser: apache2handler
>>> Command Prompt: cli
>>> I think it is of great help and we are going to have a robust
>>> solution. Meanwhile, i would appreciate if anyone of you could share
>>> the list of all possible php sapi (along with their possible
>>> applicationfrom which they will be in existence).
>>> And yes Jerry Stuckle do provided the good way of distinguish between
>>> 'not set element' and 'null element' inside the array. I was known to
>>> it, but somehow it get slipped out of my mind.
>>> Cheers! NC & Jerry Stuckle.
>>> To continue the discussion, i would like to extend it a little bit
>>> further by asking how to detect whether a request to the server has
>>> been made directly or using sockets or using CURL from the client side
>>> application?
>>> Ojas
>> No way to tell. This depends on the user agent sending information,
>> which is not reliable. For instance, depending on the site I'm
>> interfacing to in CURL, I might send some string such as "PHP-CURL", or
>> I might send the user agent the client is using (i.e. Firefox, IE, etc.).
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> Ok.
>
> That's correct, but in case someone is wishing to deny the request
> coming from the CURL or socket way, then what should be the procedure?
>
> Ojas
>

There is none. There is no way you can tell what the client is running,
other than what the client tells you. And that is not reliable.

The real question here is - what problem are you having?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Script running under Command Prompt or Browser or some other

am 06.12.2007 07:32:03 von Ojas

On Dec 6, 10:46 am, Jerry Stuckle wrote:
> Ojas wrote:
> > On Dec 6, 10:02 am, Jerry Stuckle wrote:
> >> Ojas wrote:
> >>> On Dec 6, 8:21 am, NC wrote:
> >>>> On Dec 5, 1:18 am, Ojas wrote:
> >>>>> if the request has been sent through command line, $argc &
> >>>>> $arv will exists whether having any values or not but since
> >>>>> we can access these values from $_SERVER (or $_ENV not sure
> >>>>> about it) which itself is an array, not set $_SERVER['argc']
> >>>>> is equivalent to null $_SERVER['argc'], accessing the
> >>>>> $_SERVER['argc'] will result to null values in both cases,
> >>>>> then how one can distinguish these cases?
> >>>> There's no need to. If the script is running from the command line, a
> >>>> call to php_sapi_name() will return 'cli'.
> >>>> Cheers,
> >>>> NC
> >>> Hi! all,
> >>> NC has provided a very useful point of using php_sapi_name to detect
> >>> the same. I tried to print 'PHP_SAPI' on my system and got the
> >>> following result:
> >>> Browser: apache2handler
> >>> Command Prompt: cli
> >>> I think it is of great help and we are going to have a robust
> >>> solution. Meanwhile, i would appreciate if anyone of you could share
> >>> the list of all possible php sapi (along with their possible
> >>> applicationfrom which they will be in existence).
> >>> And yes Jerry Stuckle do provided the good way of distinguish between
> >>> 'not set element' and 'null element' inside the array. I was known to
> >>> it, but somehow it get slipped out of my mind.
> >>> Cheers! NC & Jerry Stuckle.
> >>> To continue the discussion, i would like to extend it a little bit
> >>> further by asking how to detect whether a request to the server has
> >>> been made directly or using sockets or using CURL from the client side
> >>>application?
> >>> Ojas
> >> No way to tell. This depends on the user agent sending information,
> >> which is not reliable. For instance, depending on the site I'm
> >> interfacing to in CURL, I might send some string such as "PHP-CURL", or
> >> I might send the user agent the client is using (i.e. Firefox, IE, etc.).
>
> >> --
> >> ==================
> >> Remove the "x" from my email address
> >> Jerry Stuckle
> >> JDS Computer Training Corp.
> >> jstuck...@attglobal.net
> >> ==================
>
> > Ok.
>
> > That's correct, but in case someone is wishing to deny the request
> > coming from the CURL or socket way, then what should be the procedure?
>
> > Ojas
>
> There is none. There is no way you can tell what the client is running,
> other than what the client tells you. And that is not reliable.
>
> The real question here is - what problem are you having?
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

Well i am facing no problem at all at present.

I was just wishing to know it so that i could use the info in any of
my next projects/assignments.

As you said there is no way to track this, a spammer can develop a
script which will regularly send request to the web-server, forging
the original details??

Re: Script running under Command Prompt or Browser or some other application?

am 06.12.2007 14:28:57 von Jerry Stuckle

Ojas wrote:
> On Dec 6, 10:46 am, Jerry Stuckle wrote:
>> Ojas wrote:
>>> On Dec 6, 10:02 am, Jerry Stuckle wrote:
>>>> Ojas wrote:
>>>>> On Dec 6, 8:21 am, NC wrote:
>>>>>> On Dec 5, 1:18 am, Ojas wrote:
>>>>>>> if the request has been sent through command line, $argc &
>>>>>>> $arv will exists whether having any values or not but since
>>>>>>> we can access these values from $_SERVER (or $_ENV not sure
>>>>>>> about it) which itself is an array, not set $_SERVER['argc']
>>>>>>> is equivalent to null $_SERVER['argc'], accessing the
>>>>>>> $_SERVER['argc'] will result to null values in both cases,
>>>>>>> then how one can distinguish these cases?
>>>>>> There's no need to. If the script is running from the command line, a
>>>>>> call to php_sapi_name() will return 'cli'.
>>>>>> Cheers,
>>>>>> NC
>>>>> Hi! all,
>>>>> NC has provided a very useful point of using php_sapi_name to detect
>>>>> the same. I tried to print 'PHP_SAPI' on my system and got the
>>>>> following result:
>>>>> Browser: apache2handler
>>>>> Command Prompt: cli
>>>>> I think it is of great help and we are going to have a robust
>>>>> solution. Meanwhile, i would appreciate if anyone of you could share
>>>>> the list of all possible php sapi (along with their possible
>>>>> applicationfrom which they will be in existence).
>>>>> And yes Jerry Stuckle do provided the good way of distinguish between
>>>>> 'not set element' and 'null element' inside the array. I was known to
>>>>> it, but somehow it get slipped out of my mind.
>>>>> Cheers! NC & Jerry Stuckle.
>>>>> To continue the discussion, i would like to extend it a little bit
>>>>> further by asking how to detect whether a request to the server has
>>>>> been made directly or using sockets or using CURL from the client side
>>>>> application?
>>>>> Ojas
>>>> No way to tell. This depends on the user agent sending information,
>>>> which is not reliable. For instance, depending on the site I'm
>>>> interfacing to in CURL, I might send some string such as "PHP-CURL", or
>>>> I might send the user agent the client is using (i.e. Firefox, IE, etc.).
>>>> --
>>>> ==================
>>>> Remove the "x" from my email address
>>>> Jerry Stuckle
>>>> JDS Computer Training Corp.
>>>> jstuck...@attglobal.net
>>>> ==================
>>> Ok.
>>> That's correct, but in case someone is wishing to deny the request
>>> coming from the CURL or socket way, then what should be the procedure?
>>> Ojas
>> There is none. There is no way you can tell what the client is running,
>> other than what the client tells you. And that is not reliable.
>>
>> The real question here is - what problem are you having?
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> Well i am facing no problem at all at present.
>
> I was just wishing to know it so that i could use the info in any of
> my next projects/assignments.
>
> As you said there is no way to track this, a spammer can develop a
> script which will regularly send request to the web-server, forging
> the original details??
>

That's right.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Script running under Command Prompt or Browser or some other application?

am 06.12.2007 14:28:57 von Jerry Stuckle

Ojas wrote:
> On Dec 6, 10:46 am, Jerry Stuckle wrote:
>> Ojas wrote:
>>> On Dec 6, 10:02 am, Jerry Stuckle wrote:
>>>> Ojas wrote:
>>>>> On Dec 6, 8:21 am, NC wrote:
>>>>>> On Dec 5, 1:18 am, Ojas wrote:
>>>>>>> if the request has been sent through command line, $argc &
>>>>>>> $arv will exists whether having any values or not but since
>>>>>>> we can access these values from $_SERVER (or $_ENV not sure
>>>>>>> about it) which itself is an array, not set $_SERVER['argc']
>>>>>>> is equivalent to null $_SERVER['argc'], accessing the
>>>>>>> $_SERVER['argc'] will result to null values in both cases,
>>>>>>> then how one can distinguish these cases?
>>>>>> There's no need to. If the script is running from the command line, a
>>>>>> call to php_sapi_name() will return 'cli'.
>>>>>> Cheers,
>>>>>> NC
>>>>> Hi! all,
>>>>> NC has provided a very useful point of using php_sapi_name to detect
>>>>> the same. I tried to print 'PHP_SAPI' on my system and got the
>>>>> following result:
>>>>> Browser: apache2handler
>>>>> Command Prompt: cli
>>>>> I think it is of great help and we are going to have a robust
>>>>> solution. Meanwhile, i would appreciate if anyone of you could share
>>>>> the list of all possible php sapi (along with their possible
>>>>> applicationfrom which they will be in existence).
>>>>> And yes Jerry Stuckle do provided the good way of distinguish between
>>>>> 'not set element' and 'null element' inside the array. I was known to
>>>>> it, but somehow it get slipped out of my mind.
>>>>> Cheers! NC & Jerry Stuckle.
>>>>> To continue the discussion, i would like to extend it a little bit
>>>>> further by asking how to detect whether a request to the server has
>>>>> been made directly or using sockets or using CURL from the client side
>>>>> application?
>>>>> Ojas
>>>> No way to tell. This depends on the user agent sending information,
>>>> which is not reliable. For instance, depending on the site I'm
>>>> interfacing to in CURL, I might send some string such as "PHP-CURL", or
>>>> I might send the user agent the client is using (i.e. Firefox, IE, etc.).
>>>> --
>>>> ==================
>>>> Remove the "x" from my email address
>>>> Jerry Stuckle
>>>> JDS Computer Training Corp.
>>>> jstuck...@attglobal.net
>>>> ==================
>>> Ok.
>>> That's correct, but in case someone is wishing to deny the request
>>> coming from the CURL or socket way, then what should be the procedure?
>>> Ojas
>> There is none. There is no way you can tell what the client is running,
>> other than what the client tells you. And that is not reliable.
>>
>> The real question here is - what problem are you having?
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> Well i am facing no problem at all at present.
>
> I was just wishing to know it so that i could use the info in any of
> my next projects/assignments.
>
> As you said there is no way to track this, a spammer can develop a
> script which will regularly send request to the web-server, forging
> the original details??
>

That's right.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Script running under Command Prompt or Browser or some other

am 07.12.2007 16:54:13 von nc

On Dec 5, 8:05 pm, Ojas wrote:
>
> Meanwhile, i would appreciate if anyone of you could share
> the list of all possible php sapi (along with their possible
> application from which they will be in existence).

It's given in the notes to the php_sapi_name() documentation:

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

Here's the list:

- aolserver
- activescript
- apache
- cgi-fcgi
- cgi
- isapi
- nsapi
- phttpd
- roxen
- java_servlet
- thttpd
- pi3web
- apache2filter
- caudium
- apache2handler
- tux
- webjames
- cli
- embed
- milter

> To continue the discussion, i would like to extend it
> a little bit further by asking how to detect whether
> a request to the server has been made directly or using
> sockets or using CURL from the client side application?

There is no way to tell. Client-side applications (sometimes)
identify themselves by sending a "User-Agent:" request header, the
contents of which is available to a PHP script as
$_SERVER['HTTP_USER_AGENT']. However, it is possible (and, in fact,
rather easy) to configure cURL or a socket application to send ANY
"User-Agent:" header, including a header normally associated with a
Web browser. Simply put, cURL or a socket application can easily and
very convincingly pretend to be a browser...

Cheers,
NC