views:

46

answers:

3

I'm building a module for a CMS that creates its own PHP files. I've received some feedback that a lot of hosting providers don't allow PHP to have write permissions on directories where PHP scripts can be executed. Although the scripts are not technically "executable" (they're just class definitions), I'm concerned that this module may not work on a lot of users' environments.

Is this true, and if so, assuming the creation of the PHP files is non-negotiable, is there another approach I could look into?

+1  A: 

you can store the code in the database or in a text file and use eval() function to run it.

Have a look at http://www.php.net/eval

Hassan Al-Jeshi
Eval() should only be used as the very, very last resort. In fact, it would be preferable to change the script's architecture than using eval. Executing live code from the database is not a good idea.
Pekka
See e.g. http://stackoverflow.com/questions/951373/when-is-eval-evil-in-php
Pekka
A: 

The major of web hostings services allow scripts to write files, and if not, It allow you to set chmod permissions in directories and files.

(Hassan Al-Jeshi is right, he post first but I think the same)

Dorian
+1  A: 

Thanks, everyone. @Pekka makes a good point. I was erroneously thinking that "execute" is the same as simple inclusion (e.g. a class definition). These scripts don't need to be run from the URL, so I think I'm okay.

Aaron