473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

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
7 3506
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
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
>
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
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
Á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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
4
by: Matt Sawyer | last post by:
I am attempting to use an API (CxApiOem.dll) that has a large number of defines and complicated structs. It's just too much hassle to attempt to use DLLImport to make the desired API calls. ...
3
by: Double Echo | last post by:
Hi all, I'm using PHP 4.4.2, and use PHP on both the command-line and the web. I am running PHP on SuSE 10 Linux , in a VMware 5.5 workstation, using Apache 2.0.55 , on my Dell laptop. ...
1
by: Xristos Nikolopoulos | last post by:
Hello, I have made an application that needs to upload files, the application is deployed in several folders, and each folder has its php files. The problem is, I have in the folder I want to...
2
by: hup | last post by:
One of my Linux (CentOS) server stop interpret php code any more. I did try to compile and installed other version of php, but it's still not working. # cat /tmp/phpinfo.php <? phpinfo() ?>...
19
by: citronelu | last post by:
Is it possible to execute a binary string stored within a python script as executable code ? The script is run under Windows, and the binary code (a full executable file) is stored in a variable...
5
by: CDMAPoster | last post by:
I have changed how I get the shell path for Acrobat Reader based on code posted by John deKrafft. Does anyone see any problems with this code running on various Windows OS's? '--Begin Module...
15
by: tmp123 | last post by:
Hello, Thanks for your time. We have very big files with python commands (more or less, 500000 commands each file). It is possible to execute them command by command, like if the commands...
0
by: David | last post by:
- Are there any peculiarities with using curs.executemany(...) vs. multiple How many times are you calling execute vs a single executemany? The python call overhead will add up for thousands of...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.