URL、表单数据、IP等处理类 php url 参数 url 参数 数组 jquery获取url参
程序员文章站
2022-04-29 23:47:28
...
php class ev { public $cookie; public $post; public $get; public $file; public $url; public $G; private $e; public function __construct() {if (ini_get('magic_quotes_gpc')) { //判断php.ini是否有magic_quotes_gpc过滤(转义)函数 $get = $this->stripSlashes($_REQUEST); $post = $this->stripSlashes($_POST); $this->cookie = $this->stripSlashes($_COOKIE); } else { $get = $_REQUEST; $post = $_POST; $this->cookie = $_COOKIE; } $this->file = $_FILES; $this->get = $this->initData($get); $this->post = $this->initData($post); $this->url = $this->parseUrl(); $this->cookie = $this->initData($this->cookie); } //解析urlpublic function parseUrl() { if(isset($_REQUEST['route'])) { return explode('-',$_REQUEST['route']); //解析路由 } elseif(isset($_SERVER['QUERY_STRING'])) { $tmp = explode('#',$_SERVER['QUERY_STRING'],2); $tp = explode('&',$tmp[0],2); return explode('-',$tp[0]); } elsereturnfalse; } //返回$_REQUEST数组内的值public function get($par) { if(isset($this->get[$par]))return $this->get[$par]; elsereturnfalse; } //返回$_POST数组内的值public function post($par) { if(isset($this->post[$par]))return $this->post[$par]; elsereturnfalse; } //返回URL数组中的值public function url($par) { $par = intval($par); if(isset($this->url[$par]))return $this->url[$par]; elsereturnfalse; } //设置COOKIEpublic function setCookie($name,$value,$time=3600) { if($time)$time = TIME + $time; else $time = 0; if(CDO)setCookie(CH.$name,$value,$time,CP,CDO); else setCookie(CH.$name,$value,$time,CP); } //获取cookiepublic function getCookie($par,$nohead = 0) { if(isset($this->cookie[CH.$par]))return $this->cookie[CH.$par]; elseif(isset($this->cookie[$par]) && $nohead)return $this->cookie[$par]; elsereturnfalse; } //获取$_FILEpublic function getFile($par) { if(isset($this->file[$par]))return $this->file[$par]; elsereturnfalse; } //初始化数据public function initData($data) { if(is_array($data)) { foreach($data as $key => $value) { if($this->strings->isAllowKey($key) === false) { unset($data[$key]); } else $data[$key] = $this->initData($value); } return $data; } else { if(is_numeric($data)) { if($data[0] === 0)return $this->addSlashes(htmlspecialchars(str_replace("'","'",$data))); if(strlen($data) >= 11)return $this->addSlashes(htmlspecialchars(str_replace("'","'",$data))); if(strpos($data,'.'))return floatval($data); elsereturn intval($data); } if(is_string($data))return $this->addSlashes(htmlspecialchars(str_replace("'","'",$data))); if(is_bool($data))return (bool)$data; returnfalse; } } //去除转义字符public function stripSlashes($data) { if (is_array($data)) { foreach ($data as $key => $value) { $data[$key] = $this->stripSlashes($value); } } else { $data = stripSlashes(trim($data)); } return $data; } //添加转义字符public function addSlashes($data) { if (is_array($data)) { foreach ($data as $key => $value) { $data[$key] = $this->addSlashes($value); } } else { $data = addSlashes(trim($data)); } return $data; } //获取客户端IPpublic function getClientIp() { if(!isset($this->e['ip'])) { if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown")) $ip = getenv("HTTP_CLIENT_IP"); elseif (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown")) $ip = getenv("HTTP_X_FORWARDED_FOR"); elseif (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown")) $ip = getenv("REMOTE_ADDR"); elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown")) $ip = $_SERVER['REMOTE_ADDR']; else $ip = "unknown"; $this->e['ip'] = $ip; } return $this->e['ip']; } //根据二级域名获取信息public function getSecondDomain() { $domain = $_SERVER['HTTP_HOST']; $domain = str_replace(array('com.cn','net.cn','gov.cn','org.cn'),'com',$domain); $tmp = explode('.',$domain); if(count($tmp) 3
上一篇: ORACLE表分区