代码如下 | 复制代码 |
<?php /** * 参数处理类 * @author JasonWei */ class Params { public $get = array(); public $post = array(); function __construct() { if (!empty($_GET)) { foreach ($_GET as $key => $val) { if (is_numeric($val)) { $this->get[$key] = $this->getInt($val); } else { $this->get[$key] = $this->getStr($val); } } } if (!empty($_POST)) { foreach ($_POST as $key => $val) { if (is_numeric($val)) { $this->post[$key] = $this->getInt($val); } else { $this->post[$key] = $this->getStr($val); } } } } public function getInt($number) { return intval($number); } public function getStr($string) { if (!get_magic_quotes_gpc()) { $string = addslashes($string); } return $string; } public function checkInject($string) { return eregi('select|insert|update|delete|/*|*|../|./|union|into|load_file|outfile', $string); } public function verifyId($id = null) { if (!$id || $this->checkInject($id) || !is_numeric($id)) { $id = false; } else { $id = intval($id); } return $id; } } ?> |
例子二
代码如下 | 复制代码 |
<? |