0

I have an application which reads a textarea and runs the textarea as a PHP file.

The textarea content is saved in a txt file and runs with eval(file_get_contents('myfile.txt')); but I want only to allow user to use echo, if statement, for, while without using mysql(i) functions and some other functions like unlink.

EDIT A little bit more explaining: How can I disallow in a specific file using php functions like mysql and file functions ?

Is there any options to do this?

MM PP
  • 4,050
  • 9
  • 35
  • 61

2 Answers2

0

Another way, you could try php sandbox: https://github.com/fieryprophet/php-sandbox

jianfyun
  • 71
  • 1
  • 4
0

well, maybe you can use this solution. php override_function. if you really want to use eval, and make it safe. you are going to work hard. but basically if you don't want to write your private php parser like customEval(). you can just override php native functions

override_function('file_put_contents', '$a', 'echo file_put_contents not allowed...;');

the problem with that solution: if you will need one of this functions after the eval(), you can't use them. unless you'll override the override. 2nd problem, the overriding list might be long (:

Daniel Krom
  • 9,751
  • 3
  • 43
  • 44