Skip to content

Instantly share code, notes, and snippets.

@whs
Created June 15, 2010 13:18
Show Gist options
  • Save whs/439113 to your computer and use it in GitHub Desktop.
Save whs/439113 to your computer and use it in GitHub Desktop.
<?php
$allowed = array("Solve", "Simplify", "Factor", "Think");
if(!in_array($_REQUEST['method'], $allowed)) die("Bad method!");
if(strstr(";", $_REQUEST['input'])) die("Hack?");
$input = $_REQUEST['input'];
$input = str_replace("=", "==", $input);
$path = "C:\\Program Files\\Wolfram Research\\Mathematica\\7.0\\math.exe";
$cmd = $_REQUEST['method'] . "[".$input."]";
if($_REQUEST['method'] == "Think"){
$cmd = $_REQUEST['input'];
}
file_put_contents("tmpinput", "Export[\"tmpoutput.png\", ".$cmd."]\nExport[\"question.png\", ".$_REQUEST['input']."]\nExit[]");
system("\"$path\" -noprompt -run \"<<tmpinput\"");
<?php
header("Content-Type: image/png");
$allowed = array("question", "tmpoutput");
if(!in_array($_GET['file'], $allowed)) die();
print file_get_contents($_GET['file'].".png");
<!doctype html>
<html>
<head>
<meta charset="windows-874">
<title>Solver</title>
<script src="jq.js"></script>
<style>
body{
font-family: verdana, sans-serif;
}
input[type=text]{
font-size: 24pt;
width: 80%;
}
form{text-align: center;}
#output{
min-height: 200px;
text-align: center;
font-size: 32pt;
}
#footer{text-align: center; color: #bbb; margin-top: 40px;}
</style>
<script>
$(function(){
$("form").submit(function(){
$("#output").html("Loading...");
$.post("calc.php", $("form").serialize(), function(d){
$("#output").html("<img src='imgs.php?file=question&t="+new Date().getTime()+"'> = <img src='imgs.php?file=tmpoutput&t="+new Date().getTime()+"'>");
});
return false;
});
});
</script>
</head>
<body>
<form action="#">
<select name="method">
<option value="Think">คำนวน</option>
<option value="Solve">หาค่า</option>
<option value="Simplify">ทำให้อยู่ในรูปอย่างง่าย</option>
<option value="Factor">แยกตัวประกอบพหุนาม</option>
</select>
<input type="text" name="input" autofocus="true" placeholder="ใส่สูตรที่ต้องการคำนวน">
</form>
<div id="output"></div>
<div id="footer">Powered by Mathemetica</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment