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

Started by
0 comments, last by deadimp 16 years, 10 months ago
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]
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".
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire

This topic is closed to new replies.

Advertisement