Forum Moderators: coopster
Is it possible to use a php include() to insert code directly from a database? For example, if I have a file something.inc which contains the following
<?php
…. Some php statements
?>
and have in my index.php file the statement
include 'something.inc';
then the above php statements get executed. What I want to do is place the contents of something.inc in a database (say MySQL) and insert them as you would using the include statement on a file.
I can think of two possible ways to try this but both appear to have problems:
1. Write the database contents to a temporary file such as temp.inc and then use the statement
include 'temp.inc';
I think that this would break down if more than one user were present.
2. Write a php module such as code_get.inc which reads the database and echos out the contents. The include statement would then be
include 'http://www.example.com/code_get.php?foo=1';
where foo would designate the database equivalent of something.inc. I’m not sure but this looks like it may have security problems besides not being very efficient but if I read the php manual correctly it should work.
Any suggestions or is inserting code from a database just not possible?