Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're aiming for security and you want to let them to write functions, then the short answer is: no.</p> <p>Essentially you're asking for a PHP sandbox which will let you constrain what code can be executed. PHP would have to support this at a fundamental level for it to work. For example, supposing you took the approach of saying "I only allow the user to write a function named 'foo'". Inside that function, though the user can do all kinds of bad things like making system calls, downloading other code and executing it, etc. In order to prevent this you'd need to implement checks at a much lower level in the system.</p> <p>If you're willing to restrict the scope only to variable definitions then yes you can do it. You can use token_get_all() and token_name() to examine the file to make sure that it doesn't have any code that you don't want in it. For example:</p> <pre><code>foreach (token_get_all(file_get_contents("uploadedfile.php")) as $token) { if (is_array($token)) { echo token_name($token[0]), " "; } else { echo $token; } } </code></pre> <p>If you don't like any tokens you see, don't include the file. You could theoretically guard against bad functions this way as well, but it'll require a fair amount of effort to properly parse the file and make sure that they're not doing something bad.</p> <p>references:</p> <ul> <li><a href="http://www.php.net/manual/en/function.token-get-all.php" rel="nofollow">http://www.php.net/manual/en/function.token-get-all.php</a></li> <li><a href="http://www.php.net/manual/en/function.token-name.php" rel="nofollow">http://www.php.net/manual/en/function.token-name.php</a></li> <li><a href="http://www.php.net/manual/en/tokens.php" rel="nofollow">http://www.php.net/manual/en/tokens.php</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload