I am writing a system for a browser application that will store some specific php scripts in a database and then pull them out and execute them if necessary. At first I tried using exec () and piping to php the output of a script that received scripts from the database and printed them. This worked in one case, but not in all, and fragility is felt anyway, so I'm looking for the best way.
Now I am trying to accomplish this using a stream of PHP files in memory. For instance:
$thing = <<<'TEST' <?php $thing = array(); print "Testing code in here."; var_dump($thing); ?> TEST; $filename = "php://memory"; $fp = fopen($filename, "w+b"); fwrite($fp, $thing);
However, when the script is executed, nothing is printed. Is this possible with this tool, and if not, is there another way to do this? I try to avoid writing temporary files and reading from them, since I am sure that access to the file system will slow down. Is there a URL that I can provide for include to read the memory stream as if it were a file?
I do not think that eval()
will do this, because if I remember correctly, it is limited to one line.
Also, please do not answer "eval = include = hell". Users who are not administrators do not have access to write scripts stored in the database, I know that this requires special treatment during the life cycle of my application.
source share