0

I wonder is there any way that let's to dynamically load a piece of code at run time? For instance we have a simple "switch...case" statement like this:

switch($choice) {
   case 'help':
      load_from_db('help');
      break;
   case 'about':
      load_from_db('about');
      break;
}

And we have this database:

| keyword | command                          |
   help     require('help.php');
   about    echo 'Under construction.';

"load_from_db" is a function which is capable of reading from DB (we know how to do this) and execute corresponding command stored in the database (my question is this part).

Another example would be a simple "textarea" form which user can write some PHP code within and submit the form. At the server side code will be executed and result wil be shown to the user (I know this is not safe, this is just an example).

Any ideas?

2
  • 2
    bad idea.... but you can a stream wrapper and include a "file" from the db via a file descriptor like include "db://tablename/keyword"; Commented Jul 11, 2013 at 6:37
  • Given what you propose, which appears to be a menu, you could simply load a new page giving the appropriate response when it is selected. If you wish to avoid reloading the page, then you should consider using Ajax, which will allow some of the functionality you seek without the destructive potential of eval (just imagine what would happen if someone decided to start unlinking various files) Commented Jul 11, 2013 at 6:53

1 Answer 1

2

You can use, but should always avoid, http://de.php.net/eval

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.