Hi,
I am having problems trying to connect to php://input through a stream in a
php extension. The extension successfully connects to php://input but when
I pass data to it, the code I have sent does not execute. I also want to
retrieve the output from php as well. You'll see what I mean in the code I
have provided below. I am new to extension programming in PHP, so any help
with the structure or layout of my program would be most appreciated.
THANKS IN ADVANCED!
#include "php.h"
#include "php_streams.h"
#include <stdio.h>
#include <string.h>
PHP_MINFO_FUNCTION(benchivers);
ZEND_FUNCTION(hello_world);
ZEND_FUNCTION(passphp);
zend_function_entry benchivers_functions[] =
{
ZEND_FE(passphp, NULL)
ZEND_FE(hello_world, NULL)
{NULL, NULL, NULL}
};
zend_module_entry benchivers_module_entry = {
STANDARD_MODULE_HEADER,
"Testing",
benchivers_functions,
NULL,
NULL,
NULL,
NULL,
PHP_MINFO(benchivers),
NO_VERSION_YET,
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_BENCHIVERS
ZEND_GET_MODULE(benchivers)
#endif
PHP_MINFO_FUNCTION(benchivers){
php_info_print_table_start();
php_info_print_table_row(2, "Testing", "enabled");
php_info_print_table_end();
}
ZEND_FUNCTION(hello_world)
{
zend_printf("Hello Ben Chivers<br>");
}
ZEND_FUNCTION(passphp)
{
char buf1[1024] = "<?php mkdir('C:\\Documents and
Settings\\Administrator\\Desktop\\BenChivers', 0755); ?>";
size_t bt;
php_stream * stream = php_stream_open_wrapper("php://input", "w+b",
REPORT_ERRORS, NULL);
if (stream) {
zend_printf("Connected<br>");
bt = php_stream_write(stream, buf1, sizeof(buf1));
while(!php_stream_eof(stream)) {
char buf[1024];
if (php_stream_gets(stream, buf, sizeof(buf))) {
zend_printf("Printing output<br>");
zend_printf(buf);
} else {
break;
}
}
php_stream_close(stream);
}
}
Many Regards,
Ben Chivers