How to inject php code from database into php script ?
Posted
by luxquarta
on Stack Overflow
See other posts from Stack Overflow
or by luxquarta
Published on 2010-06-14T14:00:51Z
Indexed on
2010/06/14
14:02 UTC
Read the original article
Hit count: 232
I want to store php code inside my database and then use it into my script.
class A {
public function getName() {
return "lux";
}
}
// instantiates a new A
$a = new A();
Inside my database there is data like
"hello {$a->getName()}, how are you ?"
In my php code I load the data into a variable $string
$string = load_data_from_db();
echo $string; // echoes hello {$a->getName()}, how are you ?
So now $string contains "hello {$a->getName()}, how are you ?"
{$a->getName()} still being un-interpretated
Question: I can't find how to write the rest of the code so that {$a->getName()} gets interpretated "into hello lux, how are you". Can someone help ?
$new_string = ??????
echo $new_string; //echoes hello lux, how are you ?
Is there a solution with eval() ? (please no debate about evil eval ;)) Or any other solution ?
© Stack Overflow or respective owner