Page 1 of 1

Calling a CGI script from phpWCMS with arguments...

Posted: Wed 29. Dec 2004, 00:23
by fnord
After trying the "virtual" method suggested in this topic and coming across the same issue that the results of the CGI scripts are placed at top of the screen instead of in the content area where they "should" go I set out to find a better way.

I thought I had come across a smooth way of calling a cgi script (perl in my case) from within the contents of phpWCMS. I'm using this PHP code to take all of the posted arguments and pass them along to the cgi script:

Code: Select all

[PHP]
$CGISCRIPT="./cgi-bin/pregtest.cgi";
 // preparing the arguments passed to this PHP page
$QSTRING = $QUERY_STRING;

foreach ($HTTP_POST_VARS as $header=> $value ){
 if($QSTRING==""){
   $QSTRING = $header.'='.urlencode($value);
 }else{
   $QSTRING = $QSTRING.'&'.$header.'='.urlencode($value);
 }
}
 
putenv('REQUEST_METHOD=POST');
putenv('CONTENT_TYPE=application/x-www-form-urlencoded');
putenv('CONTENT_LENGTH='.strlen($QSTRING));
putenv('QUERY_STRING='.$QSTRING);
unset($return_array);
exec('echo "'.$QSTRING.'"| '.$CGISCRIPT, $return_array, $return_val);

$onestring = implode('',$return_array);
echo "$onestring";

[/PHP]
Unfortunately, it appears that the post variables that would normally be available to a php script are not available inside the [PHP] ... [/PHP] context.

Am I doing something wrong or has phpwcms not made those variables available?

Thanks in advance for any help.

fnord

Posted: Wed 29. Dec 2004, 03:30
by Karla

Isn't that the opposite?

Posted: Wed 29. Dec 2004, 05:20
by fnord
Oliver Georgi said wrote:Vars you want to use anywhere has to be brought to the $GLOBALS array first.
I think that thread is actually the opposite if what I'm trying to do. Isn't that for making my local variables in my function global so that any PHP function can use them?

What I'm looking for is a way to access the global predefined variables that PHP usually gets in my function.

I could totally be wrong but that's my understanding.

Fnord