[pmwiki-devel] Calling CGI from PHP
Petko Yotov
5ko at 5ko.fr
Fri Sep 7 02:44:39 CDT 2012
Simon writes:
> As an interim step to replacing this script (with something clever from
> PmWiki) I've tried to invoke the script from within a recipe on
> <URL:http://ttc.org.nz/pmwiki/pmwiki.php/TTC/Tuesday>a page.
>
>
> The recipe is
>
> Markup('ClubNight', 'fulltext', '/\\(:clubnight:\\)/ei',
> "Keep(ClubNight())");
> function ClubNight() {
> $retval = 'retval is ';
> $lastline = '';
> $output = '';
> // Create a stream
> $opts = array(
> 'http'=>array(
> 'method'=>"GET",
> 'header'=>"Accept-language: en\r\n"
> )
> );
> $context = stream_context_create($opts);
> // Open the file using the HTTP headers set above
> $retval .= 'a' . file_get_contents('<URL:http://ttc.org.nz/cgi-
> bin/tuesday.pl>http://ttc.org.nz/cgi-bin/tuesday.pl', false, $context);
This should work unless some restrictions are set on that PHP installation.
You may also try simply
file_get_contents('http://ttc.org.nz/cgi-bin/tuesday.pl');
> $lastline = system ('http://ttc.org.nz/cgi-bin/tuesday.pl', $output);
This would probably never work. You normally cannot execute remote files.
> $retval .= 'b' . $output;
> $lastline = exec ('http://ttc.org.nz/cgi-bin/tuesday.pl', $output);
> $retval .= 'c' . $output;
Same here.
> $lastline = exec("./cgi-bin/tuesday.pl", $output);
This will likely be "../cgi-bin/tuesday.pl" with 2 dots, because it looks
like your running pmwiki.php file is in a directory pmwiki, while the cgi-
bin directory looks like it is in the document root, and not inside the
pmwiki directory.
> return $retval;
For testing purposes, in order to see the array values rather than 'Array',
try
return pre_r($retval);
Petko
More information about the pmwiki-devel
mailing list