} if (isset($_POST["test_1"])) { class RandChar { function getRandChar($length) { $str = null; $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; $max = strlen($strPol) - 1; for ($i = 0; $i < $length; $i++) { $str .= $strPol[rand(0, $max)]; } return $str; } } $randCharObj = new RandChar(); $test_name = $randCharObj->getRandChar(10); $handle = fopen("/tmp/" . $test_name . ".cpp", "w+"); $content = $_POST["test_1"]; fwrite($handle, $content); fclose($handle); chmod("/tmp/" . $test_name . ".cpp", 0777); exec("make /tmp/" . $test_name); chmod("/tmp/" . $test_name, 0777); passthru("ulimit -t 10 && /tmp/" . $test_name); //最大执行时间 } if (isset($_POST["test_1"]) && $_POST["test_1"] != "") { ?> </pre><?php }
<?php class RandChar { function getRandChar($length) { $str = null; $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; $max = strlen($strPol) - 1; for ($i = 0; $i < $length; $i++) { $str .= $strPol[rand(0, $max)]; } return $str; } } $randCharObj = new RandChar(); $c = $randCharObj->getRandChar(20); echo $c; $con = mysqli_connect("localhost", "yuyang", "", "nightsiesta"); if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } mysqli_select_db($con, "nightsiesta"); $pp = "INSERT INTO cookiesleft VALUES('{$c}')"; mysqli_query($con, $pp);