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_stream s.h"
#include <stdio.h>
#include <string.h>
PHP_MINFO_FUNCT ION(benchivers) ;
ZEND_FUNCTION(h ello_world);
ZEND_FUNCTION(p assphp);
zend_function_e ntry benchivers_func tions[] =
{
ZEND_FE(passphp , NULL)
ZEND_FE(hello_w orld, NULL)
{NULL, NULL, NULL}
};
zend_module_ent ry benchivers_modu le_entry = {
STANDARD_MODULE _HEADER,
"Testing",
benchivers_func tions,
NULL,
NULL,
NULL,
NULL,
PHP_MINFO(bench ivers),
NO_VERSION_YET,
STANDARD_MODULE _PROPERTIES
};
#ifdef COMPILE_DL_BENC HIVERS
ZEND_GET_MODULE (benchivers)
#endif
PHP_MINFO_FUNCT ION(benchivers) {
php_info_print_ table_start();
php_info_print_ table_row(2, "Testing", "enabled");
php_info_print_ table_end();
}
ZEND_FUNCTION(h ello_world)
{
zend_printf("He llo Ben Chivers<br>");
}
ZEND_FUNCTION(p assphp)
{
char buf1[1024] = "<?php mkdir('C:\\Docu ments and
Settings\\Admin istrator\\Deskt op\\BenChivers' , 0755); ?>";
size_t bt;
php_stream * stream = php_stream_open _wrapper("php://input", "w+b",
REPORT_ERRORS, NULL);
if (stream) {
zend_printf("Co nnected<br>");
bt = php_stream_writ e(stream, buf1, sizeof(buf1));
while(!php_stre am_eof(stream)) {
char buf[1024];
if (php_stream_get s(stream, buf, sizeof(buf))) {
zend_printf("Pr inting output<br>");
zend_printf(buf );
} else {
break;
}
}
php_stream_clos e(stream);
}
}
Many Regards,
Ben Chivers
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_stream s.h"
#include <stdio.h>
#include <string.h>
PHP_MINFO_FUNCT ION(benchivers) ;
ZEND_FUNCTION(h ello_world);
ZEND_FUNCTION(p assphp);
zend_function_e ntry benchivers_func tions[] =
{
ZEND_FE(passphp , NULL)
ZEND_FE(hello_w orld, NULL)
{NULL, NULL, NULL}
};
zend_module_ent ry benchivers_modu le_entry = {
STANDARD_MODULE _HEADER,
"Testing",
benchivers_func tions,
NULL,
NULL,
NULL,
NULL,
PHP_MINFO(bench ivers),
NO_VERSION_YET,
STANDARD_MODULE _PROPERTIES
};
#ifdef COMPILE_DL_BENC HIVERS
ZEND_GET_MODULE (benchivers)
#endif
PHP_MINFO_FUNCT ION(benchivers) {
php_info_print_ table_start();
php_info_print_ table_row(2, "Testing", "enabled");
php_info_print_ table_end();
}
ZEND_FUNCTION(h ello_world)
{
zend_printf("He llo Ben Chivers<br>");
}
ZEND_FUNCTION(p assphp)
{
char buf1[1024] = "<?php mkdir('C:\\Docu ments and
Settings\\Admin istrator\\Deskt op\\BenChivers' , 0755); ?>";
size_t bt;
php_stream * stream = php_stream_open _wrapper("php://input", "w+b",
REPORT_ERRORS, NULL);
if (stream) {
zend_printf("Co nnected<br>");
bt = php_stream_writ e(stream, buf1, sizeof(buf1));
while(!php_stre am_eof(stream)) {
char buf[1024];
if (php_stream_get s(stream, buf, sizeof(buf))) {
zend_printf("Pr inting output<br>");
zend_printf(buf );
} else {
break;
}
}
php_stream_clos e(stream);
}
}
Many Regards,
Ben Chivers
Comment