473,800 Members | 3,029 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 4165
Norman Peelman wrote:
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
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.



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
That wasn't the op's question.

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

Dec 6 '07 #21
Jerry Stuckle wrote:
Norman Peelman wrote:
>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
applicati on 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

That wasn't the op's question.

I guess I took it to mean he might want to provide either a browser
interface or a terminal interface based on how the program was being
run. Possibly for scripts being run on the client machine. But i see
from the rest of the thread the true meaning of his question is now evident.

---
Norm
Dec 7 '07 #22
Greetings, Jerry Stuckle.
In reply to Your message dated Wednesday, December 5, 2007, 23:24:58,
>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
configuratio n.
If it's using php-cgi, then it's not started from the command line, is it?
You forgot that PHP-CGI *IS* a commandline executable intended to deal with
pipelined I/O from/to server.
And You still can use it instead of CLI (either knowing that or by accident).

JFYI:
<stdout>:php-cgi.exe --help
Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]
php <file[args...]

[snip]
<stdout>:php.ex e --help
Usage: php [options] [-f] <file[--] [args...]
php [options] -r <code[--] [args...]
php [options] [-B <begin_code>] -R <code[-E <end_code>] [--] [args...]
php [options] [-B <begin_code>] -F <file[-E <end_code>] [--] [args...]
php [options] -- [args...]
php [options] -a

[snip]
Not a big difference, You see. Basically no difference in general,
same [-f <filename>] syntax for both versions of interpreter.
--
Sincerely Yours, AnrDaemon <an*******@free mail.ru>

Dec 8 '07 #23
AnrDaemon wrote:
Greetings, Jerry Stuckle.
In reply to Your message dated Wednesday, December 5, 2007, 23:24:58,
>>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?

You forgot that PHP-CGI *IS* a commandline executable intended to deal with
pipelined I/O from/to server.
And You still can use it instead of CLI (either knowing that or by accident).
No, I didn't. CGI is NOT the same as CLI. CGI is started from a web
server. CLI is started from a command line. The processing and options
are not the same - which is partly why they have different names!
JFYI:
<stdout>:php-cgi.exe --help
Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]
php <file[args...]

[snip]
<stdout>:php.ex e --help
Usage: php [options] [-f] <file[--] [args...]
php [options] -r <code[--] [args...]
php [options] [-B <begin_code>] -R <code[-E <end_code>] [--] [args...]
php [options] [-B <begin_code>] -F <file[-E <end_code>] [--] [args...]
php [options] -- [args...]
php [options] -a

[snip]
Not a big difference, You see. Basically no difference in general,
same [-f <filename>] syntax for both versions of interpreter.

Ah, but there are differences. And much more than your little --help
commands show. All they have is the command line options.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Dec 8 '07 #24
Greetings, Jerry Stuckle.
In reply to Your message dated Saturday, December 8, 2007, 05:36:28,
>>>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
configuratio n.
>>If it's using php-cgi, then it's not started from the command line, is it?

You forgot that PHP-CGI *IS* a commandline executable intended to deal with
pipelined I/O from/to server.
And You still can use it instead of CLI (either knowing that or by accident).
No, I didn't. CGI is NOT the same as CLI. CGI is started from a web
server. CLI is started from a command line. The processing and options
are not the same - which is partly why they have different names!
Go ahead and study basics, please.

Your statement "they are different because they are intended to use in
different way" is silly.

While a hammer and an axe is not the same, what makes the difference if I use
them both to hammer the nails in the wall with exactly equal success?

Remember: rock was not intended to be weapon, but Abel was killed by the Kain
throwed it.
>JFYI:
<stdout>:php-cgi.exe --help
Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]
php <file[args...]

[snip]
<stdout>:php.e xe --help
Usage: php [options] [-f] <file[--] [args...]
php [options] -r <code[--] [args...]
php [options] [-B <begin_code>] -R <code[-E <end_code>] [--] [args...]
php [options] [-B <begin_code>] -F <file[-E <end_code>] [--] [args...]
php [options] -- [args...]
php [options] -a

[snip]
Not a big difference, You see. Basically no difference in general,
same [-f <filename>] syntax for both versions of interpreter.

Ah, but there are differences. And much more than your little --help
commands show. All they have is the command line options.
Show me any:

silly.php:
<?php

echo "General rant with personal attack\n";

?>

[C:\usr\sbin\php-5.2]$php.exe -f silly.php
General rant with personal attack

[C:\usr\sbin\php-5.2]$php-cgi.exe -f silly.php
General rant with personal attack

[C:\usr\sbin\php-5.2]$

Difference between CLI and CGI versions of executable is described in the
manual: CLI have forced to have argc/argv variables set and some other
things. NO OTHER difference than described in the manual.
--
Sincerely Yours, AnrDaemon <an*******@free mail.ru>

Dec 8 '07 #25
AnrDaemon wrote:
Greetings, Jerry Stuckle.
In reply to Your message dated Saturday, December 8, 2007, 05:36:28,
>>>>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
configurati on.
If it's using php-cgi, then it's not started from the command line, is it?
You forgot that PHP-CGI *IS* a commandline executable intended to deal with
pipelined I/O from/to server.
And You still can use it instead of CLI (either knowing that or by accident).
>No, I didn't. CGI is NOT the same as CLI. CGI is started from a web
server. CLI is started from a command line. The processing and options
are not the same - which is partly why they have different names!

Go ahead and study basics, please.
I have studied basics. Obviously a lot more than you have.
Your statement "they are different because they are intended to use in
different way" is silly.
Nope. CGI is not the same as CLI. And if you understood that you
wouldn't make the stupid claim that they are.
While a hammer and an axe is not the same, what makes the difference if I use
them both to hammer the nails in the wall with exactly equal success?
It makes a huge difference whether you're running PHP as a CGI or a CLI.
But you don't seem to understand that. Perhaps you don't even know
what CGI is.
Remember: rock was not intended to be weapon, but Abel was killed by the Kain
throwed it.
So what? Are you starting to troll, now?
>>JFYI:
<stdout>:ph p-cgi.exe --help
Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]
php <file[args...]

[snip]
<stdout>:php. exe --help
Usage: php [options] [-f] <file[--] [args...]
php [options] -r <code[--] [args...]
php [options] [-B <begin_code>] -R <code[-E <end_code>] [--] [args...]
php [options] [-B <begin_code>] -F <file[-E <end_code>] [--] [args...]
php [options] -- [args...]
php [options] -a

[snip]
Not a big difference, You see. Basically no difference in general,
same [-f <filename>] syntax for both versions of interpreter.

>Ah, but there are differences. And much more than your little --help
commands show. All they have is the command line options.

Show me any:
You seem to know everything. You figure it out. Hint: find out what
"CGI" stands for.
silly.php:
<?php

echo "General rant with personal attack\n";

?>

[C:\usr\sbin\php-5.2]$php.exe -f silly.php
General rant with personal attack

[C:\usr\sbin\php-5.2]$php-cgi.exe -f silly.php
General rant with personal attack
Ah, now you're starting to troll. I made no personal attack on you.
But you've now started them.
[C:\usr\sbin\php-5.2]$

Difference between CLI and CGI versions of executable is described in the
manual: CLI have forced to have argc/argv variables set and some other
things. NO OTHER difference than described in the manual.

Try again. As I suggested before - figure out what CGI is. Then you
might have a clue.

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

Dec 8 '07 #26
Ojas wrote:
>
Hi!,

NC you have provided the list of all the available PHP SAPI but forgot
to mention when we can expect which is under existence?
Probably because that cannot be known in advance.
Also, this is very high level of intrusion being able to access the
site using CURL and socket. I can remember i access one of the site
using sockets to get the result of an particular operation to be shown
on interface of one of my project without even giving reference or
link to the output generator, of-course i would not like someone else
be able to do the same on my site. In that case how can i stop this
type of accessing?

Ojas.
That's the way the web works, and there's no way to stop it. If you
don't like it, don't use HTML. Create java applets, for instance,
instead. You'll lose a fair number of customers, but others won't be
able to use cURL. Or better yet, don't even put it on the web.

Of course, you'll lose all of the search engines, also. But heck -
you'll have your security.

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

Dec 9 '07 #27
NC
On Dec 9, 5:22 am, Ojas <contacto...@gm ail.comwrote:
On Dec 7, 8:54 pm, NC <n...@iname.com wrote:
- aolserver
- activescript
- apache
- cgi-fcgi
- cgi
- isapi
- nsapi
- phttpd
- roxen
- java_servlet
- thttpd
- pi3web
- apache2filter
- caudium
- apache2handler
- tux
- webjames
- cli
- embed
- milter


NC you have provided the list of all the available PHP SAPI but
forgot to mention when we can expect which is under existence?
The names are fairly descriptive. "aolserver" , for example, means
that PHP is running under AOL Server.
Also, this is very high level of intrusion being able to access
the site using CURL and socket.
Er, and how do you think browsers access them? Through the same
sockets...
I can remember i access one of the site using sockets to get
the result of an particular operation to be shown on interface
of one of my project without even giving reference or link to
the output generator, of-course i would not like someone else
be able to do the same on my site. In that case how can i stop
this type of accessing?
You really can't. A socket program can be written to do anything a
browser does. About the only thing you can do is to obfuscate the
server-side logic by complicating the client side through the use of
Flash, Java applets, ActiveX controls, or AJAX.

Cheers,
NC
Dec 9 '07 #28
Greetings, Jerry Stuckle.
In reply to Your message dated Saturday, December 8, 2007, 07:28:22,
>Your statement "they are different because they are intended to use in
different way" is silly.
Nope. CGI is not the same as CLI. And if you understood that you
wouldn't make the stupid claim that they are.
Where I said that they are the same? Quote please, if You're not a troll.
I said that _they_ _can_ _be_ _used_ _the_ _same_ _way_ in the case mentioned
above - running scripts from commandline.
And without checking the SAPI used to run a script, You can't, in fact, be
sure that You are running under CLI or CGI interface. Other way, You can't (in
script) be sure You're running from commandline or started from server.
I saw many posts on forums discussing that "PHP is running almost fine on my
server but some glitches..." and that was the case of using CLI instead of CGI
executable.
If You want to say that it is impossible, good luck... but life isn't loose
it's colors just because You're blind.
--
Sincerely Yours, AnrDaemon <an*******@free mail.ru>

Dec 10 '07 #29
AnrDaemon wrote:
Greetings, Jerry Stuckle.
In reply to Your message dated Saturday, December 8, 2007, 07:28:22,
>>Your statement "they are different because they are intended to use in
different way" is silly.
>Nope. CGI is not the same as CLI. And if you understood that you
wouldn't make the stupid claim that they are.

Where I said that they are the same? Quote please, if You're not a troll.
I said that _they_ _can_ _be_ _used_ _the_ _same_ _way_ in the case mentioned
above - running scripts from commandline.
And without checking the SAPI used to run a script, You can't, in fact, be
sure that You are running under CLI or CGI interface. Other way, You can't (in
script) be sure You're running from commandline or started from server.
I saw many posts on forums discussing that "PHP is running almost fine on my
server but some glitches..." and that was the case of using CLI instead of CGI
executable.
If You want to say that it is impossible, good luck... but life isn't loose
it's colors just because You're blind.

CGI is not run from the command line.

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

Dec 10 '07 #30

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
9694
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
9553
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10509
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
10039
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
7584
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
6824
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5477
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...
1
4152
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
3
2953
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.