B
bill
Is there a way for a Perl script to know whether it was called via
a CGI request or through the command line?
Thanks,
-bill
a CGI request or through the command line?
Thanks,
-bill
bill said:Is there a way for a Perl script to know whether it was called via
a CGI request or through the command line?
I dunno off-hand.
But I _do_ know how to tell if it was run from a tty (command line)
or not:
perldoc -f -t
Is there a way for a Perl script to know whether it was called via
a CGI request or through the command line?
Check the environement variables ( %ENV, for example: $ENV{REMOTE_ADDR} )
bill said:Is there a way for a Perl script to know whether it was called via
a CGI request or through the command line?
Thanks,
-bill
Gregory Toomey said:(Apologies for the site to far - I just installed www.mamboserver.com on the weekend)
A. Sinan Unur said:IMHO, checking $ENV{GATEWAY_INTERFACE} interface communicates the purpose
of the code more clearly.
Environment-checking probably is the solution OP was looking for, but it
should be clear that nothing stops a command-line user from setting those
variables.
Right
Their existence doesn't prove the program was called through
the CGI.
Alan J. Flavell said:That's a matter of terminology. If it walks like a duck, and quacks
like a duck... If all the relevant requirements have been set up for
the common gateway interface, then it -is- the common gateway
interface. What it really -doesn't- prove is that the program was
invoked from a web server (HTTPD), which is presumably the real
criterion that someone asking this question would have had in mind.
But I know of no portable (i.e platform-independent) way of proving
that conclusively.
Presumably, someone running Perl code from a CLI has access to the
code itself. That being the case, they can do whatever they want
with the code, such as removing or reversing the CGI detection logic.
So if you are assuming a hostile environment, at this point you are
already screwed.
I think what the OP really wants to know is whether
the options should be gotten from CGI or from CL arguments,
agreed
and whether the output should be HTML or not.
If an authorized CLI user wishes to go out of his way to trick the
script into making life more difficult for himself, I really
couldn't care less,
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.