php+mysql-driven webpage – PHP

  php

Q(Question):

Hi!

I have a little problem:

I have php-code stored in a mysql-table.
How do i run this code?

if i echo it, i see the code, but how do i run it?

thx,
Michael

A(Answer):

Michael Volk wrote:

I have php-code stored in a mysql-table.
How do i run this code?

if i echo it, i see the code, but how do i run it?

eval() it.

http://www.php.net/eval

–= my mail address only accepts =–
–= Content-Type: text/plain =–
–= Size below 10K =–

A(Answer):

On Fri, 28 Nov 2003 11:28:39 +0100, Michael Volk wrote:

Hi!

I have a little problem:

I have php-code stored in a mysql-table. How do i run this code?

if i echo it, i see the code, but how do i run it?

thx,
Michael

eval()

</whince>
I strongly believe though, if ‘eval()’ is the answer, you’re asking the
wrong question =)

Regards,

Ian


Ian.H [Design & Development]
digiServ Network – Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.

A(Answer):

hi!
thx for that…

there is not only php-code in this field, but theres also html.
is eval() working for that to?

its a complete site with html AND php-code stored.

thx,
Michael
"Pedro Graca" <he****@hotpop.com> schrieb im Newsbeitrag
news:bq*************@ID-203069.news.uni-berlin.de…

Michael Volk wrote:

I have php-code stored in a mysql-table.
How do i run this code?

if i echo it, i see the code, but how do i run it?

eval() it.

http://www.php.net/eval

–= my mail address only accepts =–
–= Content-Type: text/plain =–
–= Size below 10K =–

A(Answer):

Michael Volk wrote:

hi!
thx for that…

there is not only php-code in this field, but theres also html.
is eval() working for that to?

IIRC eval starts in <?php context so if you have a complete webpage
including code then do:
eval("?>$page<?php");

A(Answer):

Kevin Thorpe wrote:

IIRC eval starts in <?php context so if you have a complete webpage
including code then do:
eval("?>$page<?php");

I couldn’t get eval to work with my example 🙁

So I made a function to eval my example 🙂

Hope it can help the OP

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
<code language="php" length="41 lines">
<?php
$db_value = ‘<b><?php echo phpversion(); ?></b>
foobar
<?php $x=date("Y-m-d"); ?>
foobaz
<?php echo $x; ?>
foobar again’;

echo code_eval($db_value);
echo "\n——–\n";
eval("?>$db_value<?php"); ## error here!

function code_eval($__STO_string) {
## __STO_ (security through obscurity)

// isolate all code between the php tags
preg_match_all(‘/<\?php(.*)\?>/Us’, $__STO_string, $__STO_php_code);

// eval each one of them and store each evaluation in an array
$__STO_evaled = array();
foreach ($__STO_php_code[1] as $__STO_sub_code) {
ob_start();
eval($__STO_sub_code);
$__STO_evaled[] = ob_get_clean();
}

// replace code and php tags by their result
$__STO_i = 0;
$__STO_string_evaled = $__STO_string;
while (isset($__STO_evaled[$__STO_i])) {
$__STO_string_evaled = preg_replace(‘/<\?php(.*)\?>/Us’,
$__STO_evaled[$__STO_i],
$__STO_string_evaled,
1);
++$__STO_i;
}

// return the eval’d chunk
return $__STO_string_evaled;
}
?>
</code>

–= my mail address only accepts =–
–= Content-Type: text/plain =–
–= Size below 10K =–

A(Answer):

Another way to do this is through remote include(). Use an URL in
place of a file path like this:

include("http://localhost/db_php_code.php?criteria=something");

In db_php_code.php, connect to the database and echo the code.

"Michael Volk" <mi********@t-online.de> wrote in message news:<bq*************@news.t-online.com>…

hi!
thx for that…

there is not only php-code in this field, but theres also html.
is eval() working for that to?

its a complete site with html AND php-code stored.

thx,
Michael
"Pedro Graca" <he****@hotpop.com> schrieb im Newsbeitrag
news:bq*************@ID-203069.news.uni-berlin.de…

Michael Volk wrote:

I have php-code stored in a mysql-table.
How do i run this code?

if i echo it, i see the code, but how do i run it?

eval() it.

http://www.php.net/eval

–= my mail address only accepts =–
–= Content-Type: text/plain =–
–= Size below 10K =–

LEAVE A COMMENT