473,549 Members | 3,099 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_strin g but not good because not
execute the html code/open php tag.
The same for zend_execute_sc ript :(

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 3523
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_strin g but not good because not
execute the html code/open php tag.
The same for zend_execute_sc ript :(

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_conten ts ($Path);

BAD:
// This will give you the result of the 'executed' file
$URL = "http://www.example.com/~service42/myPHPfile.php";
$PHPContent = file_get_conten ts ($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('<pr e><?php echo "hello world"; ?></pre>'); // this cannot
be execute with a simply eval :(
?>

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

if (zend_parse_par ameters(ZEND_NU M_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_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
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_strin g but not good because not
execute the html code/open php tag.
The * * * *same for zend_execute_sc ript :(
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_conten ts ($Path);

BAD:
// This will give you the result of the 'executed' file
$URL = "http://www.example.com/~service42/myPHPfile.php";
$PHPContent = file_get_conten ts ($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_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
>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_strin g but not good because not
execute the html code/open php tag.
The same for zend_execute_sc ript :(
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_conten ts ($Path);

BAD:
// This will give you the result of the 'executed' file
$URL = "http://www.example.com/~service42/myPHPfile.php";
$PHPContent = file_get_conten ts ($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('<pr e><?php echo "hello world"; ?></pre>'); // this cannot
be execute with a simply eval :(
?>

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

if (zend_parse_par ameters(ZEND_NU M_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('<pr e><?php echo "hello world"; ?></pre>');
?>

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

What really is strange is of course the content itsef:
myfunction('<pr e><?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('<pr e><?php echo "hello world"; ?></pre>');
?>

That is no C.
It looks to me like a PHPsourcebuilde r 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('<pr e><?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_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
Á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('<pr e><?php echo "hello world"; ?></pre>');
?>

That is no C.
It looks to me like a PHPsourcebuilde r 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********@gmai l.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_strin g but not good because not
execute the html code/open php tag.
The same for zend_execute_sc ript :(

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('si g.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
4002
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 live databases on the network. Is there a way, via code, when I get back in-house from being on the road to click a button, and select the backends...
4
6881
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. Instead, I created a managed C++ DLL (OneBoxAPI.dll) that wraps the desired API calls in a manner which is easy to call from C#. This way I can use the...
3
3023
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. Everything has been running flawlessly without problems. Very amazing to use VMware, it has worked beautifully. uname -a
1
2141
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 upload the php files that do the job and a php.ini file to change limits.
2
4036
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() ?> # /usr/local/bin/php -v
19
11289
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 in the script. I know I can use os.system() or os.popen() to run an external file, but these functions take as argument a string evaluated as...
5
7453
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 Code 'Support functions and constants for reading a string from the registry 'I have modified the code posted by John deKrafft slightly '----...
15
2790
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 was typed one after the other in a interactive session?
0
4015
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 calls. The relevant source code is here if you're interested: http://svn.python.org/projects/python/trunk/Modules/_sqlite/cursor.c
0
7520
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7809
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6041
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1936
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.