• Advertisement
Sign in to follow this  

[web] (solved) [php] running dynamic php code

This topic is 3871 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, in my page, I want to store php code in a database and run them selectively. One way I can think of is to use include():
Step 1) Fetch $scriptfilename from database
Step 2) include($scriptfilename);
I suppose if I do it like this, the php would run a code block depending on the scriptfilename stored in the database. The problem here is that the actual code is not stored in the database but as a separate php file. Is there a php command like:
runasphpcode( $code );
that can run a string as a block of php code ? How would you do it in other (simpler) ways ? - Thanks EDIT: Thanks, deadimp [Edited by - Wai on June 16, 2007 11:24:21 AM]

Share this post


Link to post
Share on other sites
Advertisement
I'm going to say it: eval(). However, a warning comes attached with it. If someone manages to inject any MySQL, or simply gain access to your database, your whole site is exposed from there on, and nothing will be safe.
Use caution. Or better yet, I wouldn't use it at all. The only times I use eval() are when I know what's it going to be used for, i.e. small tasks, such as creating a new class using a string, until I recently found out about "new $var".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement