PHP Sandbox
Test your PHP code with this code tester
You can test your PHP code here on many php versions.
Notes
This script works with a whitelist of functions. All functions that do not require disk, system or network access are whitelisted, others blacklisted. Max execution time is set to 3 seconds.If you find a disabled function that should be whitelisted or if you run into other problems, please use the comments section below.


Comments
http://www.php.net/manual/en/book.bc.php
Just wanted to appreciate this great work. Helps alot since it removes the need to setup php on our machine. Great work. Best thing, all calls handled via ajax which makes this pretty fast and easy. Really nice place to learn and test. Even pros will be getting much help
thanks. You can find examples of every function on this website. The sandbox is simply to test some code.
Zach
i usually use this website to test my code at work, and at home...
this has been really handy to me...
this helped me a lot to create the most complicated and handy functions, and to test them...
you enabled those functions, but you forgot to add them here:
http://onlinephpfunctions.com/categories/Type+checking+%2F+changing
(is_string and gettype)
http://onlinephpfunctions.com/categories/Uncategorized
(trigger_error and error_reporting)
and you should put the zlib functions in a new category...
If you have any questions, please use the forum.
3 secs is more than enough to run most scripts, if it takes more time (on this website), you are running very complicated calculations or you have a loop somewhere. The way to detect a loop is simply by using a time limit. The script tells you on what line the script ended (try clicking on my name for an example).
i am trying to develop some "weird" sql-like function to access array data...
and i noticed the changes, for a few seconds the code was returning weird chars...
i just sort of finished the 'drop' statement...
it's not well implemented, but will do the job...
by the way, you should set the timeout to 6 seconds, or allow to change between 3 and 6 seconds...
i don't know if it is possible, but that would be great!!!
but unfortunately, there is no way to check if you are doing an infinite loop or not...
and if you do:
for(;;){set_time_limit(1)}
this will make the code run forever, according to php page, the counter restarts, so, it's always at 0...
but you could try to create your own method to change the time only once and between 3 and 6 seconds...
Thanks for you comment! I enabled those functions.
John
error_reporting() //activates or not error reporting for that code, not on php.ini file
is_string() //this should NEVER have been blacklisted
gettype() //this only returns the type of a var (null, string, int, float...)
trigger_error() //pretty much a die() but specifies the error line and the type of error
You have to separate the code that users post totally to a save environment. I use a VPS to run the posted PHP code in a modified PHP environment. Block all outgoing ports, block all functions that handles the filesystem, and execute code as a jailed users with no permissions at all. Then return the output of the code to the main server and show it.
That is how this website works in a nutshell.
then you use the post function...
and you try to create a file with the inputed code in the textarea, using a ftp connection...
or you can also give 1 file for each user, and when they upload the code, it will be always available for them to try the code...
then you make the page to return the url with the name of the new file...
and you use that url into a iframe...
i won't explain how to do it, but you can google for jquery and jquery.post()...
thanks, I am enabling mb_convert_encoding now. For the imap functions the imap extension is required. I comes with some extra functions that I need to review first before I recompile all versions and enable it
@Harry:
thanks for your input. You are right, chr() is totally safe. I am removing it from the blacklist right now.
you can use disable functions and add all functions that can harm your system. And to be sure, run it on a vps. Thanks, John