1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| <?php ini_set('display_errors', 'Off'); class 造齿轮 { protected $朝拜圣地; protected $贡品; protected $圣殿; protected $禁地; public function __construct() { $this->朝拜圣地 = 'storage'; if (!is_dir($this->朝拜圣地)) mkdir($this->朝拜圣地); $this->禁地 = array('php', 'html', 'htaccess'); } public function 挖掘($货物, $食物) { foreach ($this->禁地 as $元素) { if (stripos($_COOKIE[$食物], $元素) !== false) { die('invaild ' . $食物); return false; } } $this->圣殿 = session_id(); return true; } public function 种植($货物, $食物) { $this->贡品 = $货物; return file_put_contents($this->朝拜圣地 . '/sess_' . $货物, $食物) === false ? false : true; } public function 收获($货物) { $this->贡品 = $货物; return (string)@file_get_contents($this->朝拜圣地 . '/sess_' . $货物); } public function 总结($货物) { if (strlen($this->圣殿) <= 0) return; return file_put_contents($this->朝拜圣地 . '/note_' . $this->圣殿, $货物) === false ? false : true; } public function 归纳() { return (string)@file_get_contents($this->朝拜圣地 . '/note_' . $this->贡品); } public function 思考($货物) { $this->贡品 = $货物; if (file_exists($this->朝拜圣地 . '/sess_' . $货物)) { unlink($this->朝拜圣地 . '/sess_' . $货物); } return true; } public function 反省($货物) { foreach (glob($this->朝拜圣地 . '/*') as $元素) { if (filemtime($元素) + $货物 < time() && file_exists($元素)) { unlink($元素); } } return true; } public function 完毕() { return true; } public function __destruct() { $this->总结($this->归纳()); } } $齿轮 = new 造齿轮(); session_set_save_handler(array($齿轮, '挖掘'), array($齿轮, '完毕'), array($齿轮, '收获'), array($齿轮, '种植'), array($齿轮, '反省'), array($齿轮, '完毕')); session_start(); srand(mktime(0, 0, 0, 0, 0, 0)); $盛世 = array(rand() => array('alice', 1), rand() => array('bob', 5), rand() => array('cat', 20), rand() => array('dog', 15), rand() => array('evil', 5), rand() => array('flag', 9999)); function 化缘() { return $_SESSION['balance']; } function 取经() { global $盛世; $宝藏 = '['; foreach ($_SESSION['items'] as $元素) $宝藏 .= $盛世[$元素][0] . ', '; $宝藏 .= ']'; return $宝藏; } function 念经() { global $齿轮; return $齿轮->归纳(); } function 造世() { global $盛世; $宝藏 = ''; foreach ($盛世 as $按键 => $元素) $宝藏 .= '<div class="item"><form method="POST"><div class="form-group">' . $元素[0] . '</div><div class="form-group"><input type="hidden" name="id" value="' . $按键 . '"><button type="submit" class="btn btn-success">buy ($' . $元素[1] . ')</button></div></form></div>'; return $宝藏; } if (!isset($_SESSION['balance'])) $_SESSION['balance'] = 2233; if (!isset($_SESSION['items'])) $_SESSION['items'] = []; if (!isset($_SESSION['note'])) $_SESSION['note'] = ''; if (isset($_POST['id'])) { if ($_SESSION['balance'] >= $盛世[$_POST['id']][1]) { $_SESSION['balance'] = $_SESSION['balance'] - $盛世[$_POST['id']][1]; array_push(${'_SESSION'}['items'], $_POST['id']); echo ('<span style="color:green">buy succ!</span>'); } else { echo ('<span style="color:red">lack of balance!</span>'); } } if (isset($_POST['note'])) { if (strlen($_POST['note']) <= 1 << 10) { $齿轮->总结(str_replace(array('&', '<', '>'), array('&', '<', '>'), $_POST['note'])); echo ('<span style="color:green">write succ!</span>'); } else { echo ('<span style="color:red">note too long!</span>'); } }
|