By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,206 Members | 1,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,206 IT Pros & Developers. It's quick & easy.

How to execute php code (with zend api) without open file

P: n/a
Hi all,
I've a problem... I'm writing an extension for php, and i need to
execute a file php... but only the content of the file and not the
file...
Now I better explain:
- the extension get the file content of a php file (php code and html
code mixed..)
- execute the content with some zend api function

I've already tried with zend_eval_string but not good because not
execute the html code/open php tag.
The same for zend_execute_script :(

If someone has used the zend api, i need your help

PS: sorry for my english, it is difficult to explain my goals :(
Nov 18 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Service4PC schreef:
Hi all,
I've a problem... I'm writing an extension for php, and i need to
execute a file php... but only the content of the file and not the
file...
Now I better explain:
- the extension get the file content of a php file (php code and html
code mixed..)
- execute the content with some zend api function

I've already tried with zend_eval_string but not good because not
execute the html code/open php tag.
The same for zend_execute_script :(

If someone has used the zend api, i need your help

PS: sorry for my english, it is difficult to explain my goals :(
Hi,

Maybe I understand wrong, but if you need the raw PHP file, simply use
the fylesystem functions to do so, and NO URL wrapper.

for example:
GOOD:
// This will get the content of your PHP file
$Path = "/home/service42/public_html/myPHPfile.php";
$PHPContent = file_get_contents ($Path);

BAD:
// This will give you the result of the 'executed' file
$URL = "http://www.example.com/~service42/myPHPfile.php";
$PHPContent = file_get_contents ($URL);

Regards,
Erwin Moller
Read more here:
http://nl3.php.net/manual/en/ref.filesystem.php

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Nov 18 '08 #2

P: n/a
An example maybe clarify the ideas...

file php:
<?php
myfunction('<pre><?php echo "hello world"; ?></pre>'); // this cannot
be execute with a simply eval :(
?>

file extension.c
[...]
PHP_FUNCTION(myfunction)
{
char *code;
int code_len;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &code,
&code_len) == FAILURE) {
RETURN_NULL();
}

// how i can execute the source code of variable code????
// ...
}
[...]

i hope this help to explain my idea...

On 18 Nov, 13:04, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
Service4PC schreef:
Hi all,
I've a problem... I'm writing an extension for php, and i need to
execute a file php... but only the content of the file and not the
file...
Now I better explain:
*- the extension get the file content of a php file (php code and html
code mixed..)
*- execute the content with some zend api function
I've already tried with zend_eval_string but not good because not
execute the html code/open php tag.
The * * * *same for zend_execute_script :(
If someone has used the zend api, i need your help
PS: sorry for my english, it is difficult to explain my goals :(

Hi,

Maybe I understand wrong, but if you need the raw PHP file, simply use
the fylesystem functions to do so, and NO URL wrapper.

for example:
GOOD:
// This will get the content of your PHP file
$Path = "/home/service42/public_html/myPHPfile.php";
$PHPContent = file_get_contents ($Path);

BAD:
// This will give you the result of the 'executed' file
$URL = "http://www.example.com/~service42/myPHPfile.php";
$PHPContent = file_get_contents ($URL);

Regards,
Erwin Moller

Read more here:http://nl3.php.net/manual/en/ref.filesystem.php

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Nov 18 '08 #3

P: n/a
>
On 18 Nov, 13:04, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
>Service4PC schreef:
>>Hi all,
I've a problem... I'm writing an extension for php, and i need to
execute a file php... but only the content of the file and not the
file...
Now I better explain:
- the extension get the file content of a php file (php code and html
code mixed..)
- execute the content with some zend api function
I've already tried with zend_eval_string but not good because not
execute the html code/open php tag.
The same for zend_execute_script :(
If someone has used the zend api, i need your help
PS: sorry for my english, it is difficult to explain my goals :(
Hi,

Maybe I understand wrong, but if you need the raw PHP file, simply use
the fylesystem functions to do so, and NO URL wrapper.

for example:
GOOD:
// This will get the content of your PHP file
$Path = "/home/service42/public_html/myPHPfile.php";
$PHPContent = file_get_contents ($Path);

BAD:
// This will give you the result of the 'executed' file
$URL = "http://www.example.com/~service42/myPHPfile.php";
$PHPContent = file_get_contents ($URL);

Regards,
Erwin Moller

Read more here:http://nl3.php.net/manual/en/ref.filesystem.php

Service4PC schreef:
An example maybe clarify the ideas...

file php:
<?php
myfunction('<pre><?php echo "hello world"; ?></pre>'); // this cannot
be execute with a simply eval :(
?>

file extension.c
[...]
PHP_FUNCTION(myfunction)
{
char *code;
int code_len;

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &code,
&code_len) == FAILURE) {
RETURN_NULL();
}

// how i can execute the source code of variable code????
// ...
}
[...]

i hope this help to explain my idea...
Hi,

[Please don't toppost, fixed]

I am still a bit at a loss.
You php file was this:
<?php
myfunction('<pre><?php echo "hello world"; ?></pre>');
?>

What do you expect from that file?
I mean: You can get its content via normal filesystemfunctions as I
described in my earlier post.

What really is strange is of course the content itsef:
myfunction('<pre><?php echo "hello world"; ?></pre>');

That is NOT executed PHP code: The "hello world" is not echo'ed at all.
It is just the literal string '<pre><?php echo "hello world"; ?></pre>'
being passed to some function.

I don't know how your application is set up or supposed to do, but this
looks like strange design to at first sight.
I might be missing something though...

Are you maybe writing some parser that will produce PHP sourcefiles itself?
(Then it would make sense.)

So sorry, it is still not clear to me. :-/

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Nov 18 '08 #4

P: n/a
Erwin Moller escribió:
I might be missing something though...

Are you maybe writing some parser that will produce PHP sourcefiles itself?
(Then it would make sense.)

So sorry, it is still not clear to me. :-/
The OP is not writing PHP code. He's writing C code: a PHP extension to
add new functions to PHP.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Nov 18 '08 #5

P: n/a
Álvaro G. Vicario schreef:
Erwin Moller escribió:
>I might be missing something though...

Are you maybe writing some parser that will produce PHP sourcefiles
itself?
(Then it would make sense.)

So sorry, it is still not clear to me. :-/

The OP is not writing PHP code. He's writing C code: a PHP extension to
add new functions to PHP.
Hi,

I understand that, but how does that explain this file he is working on
and posted as a troublesome example?

file php:
<?php
myfunction('<pre><?php echo "hello world"; ?></pre>');
?>

That is no C.
It looks to me like a PHPsourcebuilder application.

But maybe we better let Service4PC comment on it, since I am only
guessing here. I don't write PHP extensions myself.

Regards,
Erwin Moller
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Nov 18 '08 #6

P: n/a
I don't need to write any line of php code, i want to write a php
extension in c, the file php that i've posted is an example of the use
of my "function".
The php source content of the file for me is useless, because it will
passed to function without fopen (i've already the content, for this i
need this behavior).
This example:
<?php
myfunction('<pre><?php echo "hello world"; ?></pre>');
?>
is only the final result of creation of my extension, extending the
set of php functions with some "custom", the example just wanted to
clarify how the ideas will be used later.

The behavior should be as follows:
- The parameter (block of php code) is passed to my function
- The function internally prepare (in some way that I do not know)
the parameter
- Run (eg. eval) the code block

On Nov 18, 7:06 pm, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@spam yourself.comwrote:
Álvaro G. Vicario schreef:
Erwin Moller escribió:
I might be missing something though...
Are you maybe writing some parser that will produce PHP sourcefiles
itself?
(Then it would make sense.)
So sorry, it is still not clear to me. :-/
The OP is not writing PHP code. He's writing C code: a PHP extension to
add new functions to PHP.

Hi,

I understand that, but how does that explain this file he is working on
and posted as a troublesome example?

file php:
<?php
myfunction('<pre><?php echo "hello world"; ?></pre>');
?>

That is no C.
It looks to me like a PHPsourcebuilder application.

But maybe we better let Service4PC comment on it, since I am only
guessing here. I don't write PHP extensions myself.

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Nov 18 '08 #7

P: n/a
On Tue, 18 Nov 2008 00:56:21 -0800 (PST), se********@gmail.com wrote:
Hi all,
I've a problem... I'm writing an extension for php, and i need to
execute a file php... but only the content of the file and not the
file...
Now I better explain:
- the extension get the file content of a php file (php code and html
code mixed..)
- execute the content with some zend api function
So, what is your overall goal? What, exactly, does your extension
do? It may be possible an extension doing what you want exists in
the PECL repository. It might also be possible what you're
attempting can be done natively in PHP.
I've already tried with zend_eval_string but not good because not
execute the html code/open php tag.
The same for zend_execute_script :(

If someone has used the zend api, i need your help
Perhaps I'm too ignorant of PHP extension authoring, but I wasn't
able to turn up much documentation on the Zend API through web
searches. One of the best resources I did find was php.net's
documentation and the user notes.

<URL:http://php.net/manual/en/internals2.ze1.zendapi.php>
PS: sorry for my english, it is difficult to explain my goals :(
That's nothing to apologize for.

--
Curtis
$email = str_replace('sig.invalid', 'gmail.com', $from);
Nov 19 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.