473,789 Members | 1,966 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 #1
51 4162
NC
On Nov 27, 9:34 pm, Ojas <contacto...@gm ail.comwrote:
>
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_AGEN T"].

Cheers,
NC
Nov 28 '07 #2
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
Nov 28 '07 #3
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.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Nov 28 '07 #4
On Nov 28, 11:26 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
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.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attgl obal.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
Nov 29 '07 #5
>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?
Nov 29 '07 #6
Ojas wrote:
On Nov 28, 11:26 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
>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
applicatio n 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...@attg lobal.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.
js*******@attgl obal.net
=============== ===

Nov 29 '07 #7
On 29 Nov, 11:51, Bruno Rafael Moreira de Barros
<brunormbar...@ gmail.comwrote:
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.
Nov 29 '07 #8
On Nov 29, 4:51 pm, Bruno Rafael Moreira de Barros
<brunormbar...@ gmail.comwrote:
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.
Dec 5 '07 #9
Ojas wrote:
On Nov 29, 4:51 pm, Bruno Rafael Moreira de Barros
<brunormbar...@ gmail.comwrote:
>>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_exist s(), for instance.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Dec 5 '07 #10

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
9656
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
10177
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...
1
10121
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
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...
0
8995
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7519
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
5539
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4076
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.