Jump to content

[SOLVED] Eval Code


seventheyejosh

Recommended Posts

Ok I'll try again :)

 

I've always stayed away from eval because it confuses me a little :D. I've read over php.net's examples many times now, but something still isn't clicking.

 

I was just throwing out an example but i guess my question is, is it possible to run stored code from the data base? Like say I have this piece of code:

 


$username=$_SESSION['user'];

echo "Username is $username";

 

Now, is there a way for me to save that in a text field (or watever field is applicable) then query the DB, get that snippet, and run it as code? As far as I understood that is what eval is used for. I've tried and failed miserably to run it, moving around \ and " and $ to no avail in my evals :o.

 

So my question is, if I had that string in the DB and I got it, like so:

 


$res=mysql_query("SELECT * FROM `strings` WHERE `id`='1'");
$row=mysql_fetch_array($res);

$string=$row['string'];

 

String now has the aforementioned username/session code in it. So how can I tell php it is code and run it?

 

Thanks to all, and sorry to ramble and confuse. Eval is one thing I've never been able to get!

Link to comment
https://forums.phpfreaks.com/topic/165256-solved-eval-code/#findComment-871984
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.