Forum Moderators: coopster

Message Too Old, No Replies

include code directly from a database

         

Disabled Master

10:02 am on Feb 6, 2004 (gmt 0)

10+ Year Member



I searched through the forums and didn’t see a discussion of my question so here it goes.

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?

justageek

1:13 pm on Feb 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've done it before and it works OK. Take a look at the eval() function on the php site and you will find the answers and some examples.

JAG

Disabled Master

5:09 pm on Feb 6, 2004 (gmt 0)

10+ Year Member



Thanks justageek. That was exactly what I was looking for.