473,800 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Script running under Command Prompt or Browser or some otherapplicatio n?

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.
Nov 28 '07
51 4166
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 <an*******@free mail.ru>

Dec 5 '07 #11
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.
js*******@attgl obal.net
=============== ===

Dec 5 '07 #12
NC
On Dec 5, 1:18 am, Ojas <contacto...@gm ail.comwrote:
>
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
Dec 6 '07 #13
On Dec 6, 8:21 am, NC <n...@iname.com wrote:
On Dec 5, 1:18 am, Ojas <contacto...@gm ail.comwrote:
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
Dec 6 '07 #14
Ojas wrote:
On Dec 6, 8:21 am, NC <n...@iname.com wrote:
>On Dec 5, 1:18 am, Ojas <contacto...@gm ail.comwrote:
>>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.
js*******@attgl obal.net
=============== ===

Dec 6 '07 #15
On Dec 6, 10:02 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Ojas wrote:
On Dec 6, 8:21 am, NC <n...@iname.com wrote:
On Dec 5, 1:18 am, Ojas <contacto...@gm ail.comwrote:
>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...@attgl obal.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
Dec 6 '07 #16
Ojas wrote:
On Dec 6, 10:02 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>Ojas wrote:
>>On Dec 6, 8:21 am, NC <n...@iname.com wrote:
On Dec 5, 1:18 am, Ojas <contacto...@gm ail.comwrote:
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
applicationfr om 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...@attg lobal.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.
js*******@attgl obal.net
=============== ===

Dec 6 '07 #17
On Dec 6, 10:46 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Ojas wrote:
On Dec 6, 10:02 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Ojas wrote:
On Dec 6, 8:21 am, NC <n...@iname.com wrote:
On Dec 5, 1:18 am, Ojas <contacto...@gm ail.comwrote:
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
applicationfro m 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...@attgl obal.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...@attgl obal.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??
Dec 6 '07 #18
Jerry Stuckle wrote:
Kailash Nadh wrote:
>On Nov 28, 5:34 am, Ojas <contacto...@gm ail.comwrote:
>>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.


If the OP is trying to determine weather the program is running via a
internet server/browser or command line (terminal) then check this out.

Either of these two lines will tell you:

echo PHP_SAPI."\n\r" ;

or:

echo php_sapi_name() ."\n";

....see: http://us.php.net/manual/en/features.commandline.php

---
Norm
Dec 6 '07 #19
Ojas wrote:
On Dec 6, 10:46 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>Ojas wrote:
>>On Dec 6, 10:02 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Ojas wrote:
On Dec 6, 8:21 am, NC <n...@iname.com wrote:
>On Dec 5, 1:18 am, Ojas <contacto...@gm ail.comwrote:
>>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
>>$_SERVE R['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
interfacin g 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...@at tglobal.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...@attg lobal.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.
js*******@attgl obal.net
=============== ===

Dec 6 '07 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
12733
by: LayneMitch via WebmasterKB.com | last post by:
Hello. I posted this earlier with the full code of the JavaScript file I'm trying to open. I'm posting this again, because the file is not the problem. I seem to be having a 'windows' problem w/ Window Script Host. While this is more of a computer support based problem, I was hoping that someone had any knowledge on how to resolve this situation. The error message I'm getting is:
0
9695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10514
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10287
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10042
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7588
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5479
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5616
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3770
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2956
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.