Connecting Tech Pros Worldwide Help | Site Map

getting arguments from a shellscript into $_REQUEST when faking callfrom a web server

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 02:15 PM
Geoff Winkless
Guest
 
Posts: n/a
Default getting arguments from a shellscript into $_REQUEST when faking callfrom a web server

Hi

My knowledge of php is regrettably poor but I need to call a third-party
php script from within a bash cgi script (don't ask why, it's a long
story). Now normally (with eg perl-cgi) to do this I need to set
QUERY_STRING and REQUEST_METHOD appropriately; however with php this
doesn't work, the $_REQUEST array is empty.

$ export QUERY_STRING='test=1&wibble=2';export REQUEST_METHOD=GET;php -n
-r 'print_r($_REQUEST);'
Array
(
)
$

What do I need to set in order for the _REQUEST variable to be populated
correctly?

Thanks!

Geoff

  #2  
Old July 17th, 2005, 02:15 PM
Jerry Stuckle
Guest
 
Posts: n/a
Default Re: getting arguments from a shellscript into $_REQUEST when fakingcall from a web server

Geoff Winkless wrote:[color=blue]
> Hi
>
> My knowledge of php is regrettably poor but I need to call a third-party
> php script from within a bash cgi script (don't ask why, it's a long
> story). Now normally (with eg perl-cgi) to do this I need to set
> QUERY_STRING and REQUEST_METHOD appropriately; however with php this
> doesn't work, the $_REQUEST array is empty.
>
> $ export QUERY_STRING='test=1&wibble=2';export REQUEST_METHOD=GET;php -n
> -r 'print_r($_REQUEST);'
> Array
> (
> )
> $
>
> What do I need to set in order for the _REQUEST variable to be populated
> correctly?
>
> Thanks!
>
> Geoff[/color]

Geoff,

$_REQUEST is filled in by the web server interface. They do not come from the
environment. There also are no $_GET, $_SERVER or similar web server associated
values. If you needed these, you would have to call another PHP program to set
the values, then include the program you want to run.

If you want to write them to the environment, you can get them through the $_ENV
array. But an easier way is to just use argc and argv to access the values as
command line variables, i.e.

myprog test=1 wibble=2

The program will receive:

argc=2
argv[0] = "myprog"
argv[1] = "test=1"
argv[2] = "wibble=2"

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  #3  
Old July 17th, 2005, 02:15 PM
Geoff Winkless
Guest
 
Posts: n/a
Default Re: getting arguments from a shellscript into $_REQUEST when fakingcall from a web server

Jerry Stuckle wrote:[color=blue]
> $_REQUEST is filled in by the web server interface. They do not come
> from the environment. There also are no $_GET, $_SERVER or similar web
> server associated values. If you needed these, you would have to call
> another PHP program to set the values, then include the program you want
> to run.[/color]

Mmm. I managed to get it to run by using

php -r '$_REQUEST["test"]=1; include myprog.php;'

but I wasn't 100% happy with it.

Thanks anyway :)

Geoff
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.