Last active
August 29, 2015 13:59
-
-
Save martynchamberlin/10501884 to your computer and use it in GitHub Desktop.
Simple PHP evaluluator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Often times in development, I find it convenient to test something out in | |
* the rough before I actually implement it in the software I'm working on. | |
* Usually this is to get the parameters and "ropes" of a built-in function | |
* into my head before testing it in a real (i.e., more moving parts, and | |
* therefore more difficult to debug) environment. I do this in whatever | |
* language I happen to be working in — whether that be Java, C#, or PHP. | |
* | |
* In terminal, you can run `php -a` to simulate a quick PHP test. That is | |
* fine and dandy except that the data isn't persistent and it's a hassle to | |
* edit the text since your cursor isn't around. That's why I built this. | |
* Everything is based on cookies so that you can go right where you left off. | |
* Perfect for running at localhost (or in my case, since I'm already using | |
* localhost, localhost.com) to prove a point with a friend or demonstrate | |
* some new concept you've learned. | |
*/ | |
if ( isset ( $_POST['php'] ) ) | |
{ | |
setcookie( 'php', $_POST['php'], time() * 100 ); | |
header('location: http://localhost.com' ); | |
exit; | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="resources/jquery.min.js"></script> | |
<script src="resources/keymaster.js"></script> | |
<script src="resources/textarea.js"></script> | |
<script src="resources/jquery.text-expander.js"></script> | |
<script> | |
jQuery(function($) | |
{ | |
key('⌘+s', function() | |
{ | |
jQuery('form').submit(); | |
return false; | |
}); | |
$('textarea').tabby().focus(); | |
}); | |
</script> | |
<style> | |
body { | |
margin: 0; | |
padding: 0; | |
outline: none; | |
font: 16px/25px Georgia; | |
} | |
.outer { | |
background: #efe4d6; | |
padding: 30px 0 40px; | |
} | |
.wrap { | |
width: 660px; | |
margin: 0 auto; | |
} | |
textarea { | |
width: 620px; | |
height: 260px; | |
border: none; | |
display: block; | |
font-family: monospace; | |
font-size: 16px; | |
padding: 40px 20px 20px; | |
outline: none; | |
color: #407958; | |
background: #1a1a1a; | |
resize: vertical; | |
border-radius: 5px; | |
box-shadow: 0 11px 24px rgba(0, 0, 0, .34); | |
} | |
input { | |
text-align: center; | |
display: block; | |
margin: 0 auto 30px; | |
width: auto; | |
border: none; | |
background: #0085FF; | |
color: #FFF; | |
padding: 12px 20px; | |
font-family: 'Georgia'; | |
cursor: pointer; | |
font-size: 16px; | |
outline: none; | |
} | |
form { | |
position: relative; | |
} | |
.output { | |
border-top: 2px solid #C2BAAF; | |
margin: 0; | |
padding: 30px; | |
} | |
.buttons { | |
position: absolute; | |
top: 7px; | |
left: 7px; | |
} | |
.buttons div { | |
width: 12px; | |
height: 12px; | |
border-radius: 50%; | |
float: left; | |
margin: 0 9px 0 0; | |
cursor: pointer; | |
} | |
.buttons .red { | |
background: #f15751; | |
} | |
.buttons .orange { | |
background: #fbd681; | |
} | |
.buttons .green { | |
background: #8bc668; | |
} | |
.clear { | |
clear: both; | |
overflow: hidden; | |
} | |
</style> | |
</head> | |
</html> | |
<div class="outer"> | |
<div class="wrap"><form method="post" action="http://localhost.com/"> | |
<div class="buttons"> | |
<div class="red"></div> | |
<div class="orange"></div> | |
<div class="green"></div> | |
</div> | |
<textarea name="php"><? if ( isset( $_COOKIE['php'] ) ) echo $_COOKIE['php']; ?></textarea> | |
<!--<input type="submit" value="Evaluate">--> | |
</form> | |
<div class="clear"></div> | |
</div> | |
</div> | |
<div class="output"> | |
<?php | |
if ( isset ( $_COOKIE['php'] ) ) { | |
eval( $_COOKIE['php'] ); | |
} | |
?> | |
</div> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment