URL、表单数据、IP等处理类,url表单
<?<span>php </span><span>class</span><span> ev { </span><span>public</span><span> $cookie; </span><span>public</span><span> $post; </span><span>public</span> $<span>get</span><span>; </span><span>public</span><span> $file; </span><span>public</span><span> $url; </span><span>public</span><span> $G; </span><span>private</span><span> $e; </span><span>public</span> function __construct(<span>) {</span><span>if</span> (ini_get(<span>'</span><span>magic_quotes_gpc</span><span>'</span><span>)) { //判断php.ini是否有<span>magic_quotes_gpc</span>过滤(转义)函数 $</span><span>get</span> = $<span>this</span>-><span>stripSlashes($_REQUEST); $post </span>= $<span>this</span>-><span>stripSlashes($_POST); $</span><span>this</span>->cookie = $<span>this</span>-><span>stripSlashes($_COOKIE); } </span><span>else</span><span> { $</span><span>get</span> =<span> $_REQUEST; $post </span>=<span> $_POST; $</span><span>this</span>->cookie =<span> $_COOKIE; } $</span><span>this</span>->file =<span> $_FILES; $</span><span>this</span>-><span>get</span> = $<span>this</span>->initData($<span>get</span><span>); $</span><span>this</span>->post = $<span>this</span>-><span>initData($post); $</span><span>this</span>->url = $<span>this</span>-><span>parseUrl(); $</span><span>this</span>->cookie = $<span>this</span>->initData($<span>this</span>-><span>cookie); } </span><span>//</span><span>解析url</span> <span>public</span><span> function parseUrl() { </span><span>if</span>(isset($_REQUEST[<span>'</span><span>route</span><span>'</span><span>])) { </span><span>return</span> explode(<span>'</span><span>-</span><span>'</span>,$_REQUEST[<span>'</span><span>route</span><span>'</span><span>]); //解析路由 } elseif(isset($_SERVER[</span><span>'</span><span>QUERY_STRING</span><span>'</span><span>])) { $tmp </span>= explode(<span>'</span><span>#</span><span>'</span>,$_SERVER[<span>'</span><span>QUERY_STRING</span><span>'</span>],<span>2</span><span>); $tp </span>= explode(<span>'</span><span>&</span><span>'</span>,$tmp[<span>0</span>],<span>2</span><span>); </span><span>return</span> explode(<span>'</span><span>-</span><span>'</span>,$tp[<span>0</span><span>]); } </span><span>else</span> <span>return</span> <span>false</span><span>; } </span><span>//</span><span>返回$_REQUEST数组内的值</span> <span>public</span> function <span>get</span><span>($par) { </span><span>if</span>(isset($<span>this</span>-><span>get</span>[$par]))<span>return</span> $<span>this</span>-><span>get</span><span>[$par]; </span><span>else</span> <span>return</span> <span>false</span><span>; } </span><span>//</span><span>返回$_POST数组内的值</span> <span>public</span><span> function post($par) { </span><span>if</span>(isset($<span>this</span>->post[$par]))<span>return</span> $<span>this</span>-><span>post[$par]; </span><span>else</span> <span>return</span> <span>false</span><span>; } </span><span>//</span><span>返回URL数组中的值</span> <span>public</span><span> function url($par) { $par </span>=<span> intval($par); </span><span>if</span>(isset($<span>this</span>->url[$par]))<span>return</span> $<span>this</span>-><span>url[$par]; </span><span>else</span> <span>return</span> <span>false</span><span>; } </span><span>//</span><span>设置COOKIE</span> <span>public</span> function setCookie($name,$value,$time=<span>3600</span><span>) { </span><span>if</span>($time)$time = TIME +<span> $time; </span><span>else</span> $time = <span>0</span><span>; </span><span>if</span><span>(CDO)setCookie(CH.$name,$value,$time,CP,CDO); </span><span>else</span><span> setCookie(CH.$name,$value,$time,CP); } </span><span>//</span><span>获取cookie</span> <span>public</span> function getCookie($par,$nohead = <span>0</span><span>) { </span><span>if</span>(isset($<span>this</span>->cookie[CH.$par]))<span>return</span> $<span>this</span>-><span>cookie[CH.$par]; elseif(isset($</span><span>this</span>->cookie[$par]) && $nohead)<span>return</span> $<span>this</span>-><span>cookie[$par]; </span><span>else</span> <span>return</span> <span>false</span><span>; } </span><span>//</span><span>获取$_FILE</span> <span>public</span><span> function getFile($par) { </span><span>if</span>(isset($<span>this</span>->file[$par]))<span>return</span> $<span>this</span>-><span>file[$par]; </span><span>else</span> <span>return</span> <span>false</span><span>; } </span><span>//</span><span>初始化数据</span> <span>public</span><span> function initData($data) { </span><span>if</span><span>(is_array($data)) { </span><span>foreach</span>($data <span>as</span> $key =><span> $value) { </span><span>if</span>($<span>this</span>->strings->isAllowKey($key) === <span>false</span><span>) { unset($data[$key]); } </span><span>else</span><span> $data[$key] </span>= $<span>this</span>-><span>initData($value); } </span><span>return</span><span> $data; } </span><span>else</span><span> { </span><span>if</span><span>(is_numeric($data)) { </span><span>if</span>($data[<span>0</span>] === <span>0</span>)<span>return</span> $<span>this</span>->addSlashes(htmlspecialchars(str_replace(<span>"</span><span>'</span><span>"</span>,<span>"</span><span>'</span><span>"</span><span>,$data))); </span><span>if</span>(strlen($data) >= <span>11</span>)<span>return</span> $<span>this</span>->addSlashes(htmlspecialchars(str_replace(<span>"</span><span>'</span><span>"</span>,<span>"</span><span>'</span><span>"</span><span>,$data))); </span><span>if</span>(strpos($data,<span>'</span><span>.</span><span>'</span>))<span>return</span><span> floatval($data); </span><span>else</span> <span>return</span><span> intval($data); } </span><span>if</span>(is_string($data))<span>return</span> $<span>this</span>->addSlashes(htmlspecialchars(str_replace(<span>"</span><span>'</span><span>"</span>,<span>"</span><span>'</span><span>"</span><span>,$data))); </span><span>if</span>(is_bool($data))<span>return</span> (<span>bool</span><span>)$data; </span><span>return</span> <span>false</span><span>; } } </span><span>//</span><span>去除转义字符</span> <span>public</span><span> function stripSlashes($data) { </span><span>if</span><span> (is_array($data)) { </span><span>foreach</span> ($data <span>as</span> $key =><span> $value) { $data[$key] </span>= $<span>this</span>-><span>stripSlashes($value); } } </span><span>else</span><span> { $data </span>=<span> stripSlashes(trim($data)); } </span><span>return</span><span> $data; } </span><span>//</span><span>添加转义字符</span> <span>public</span><span> function addSlashes($data) { </span><span>if</span><span> (is_array($data)) { </span><span>foreach</span> ($data <span>as</span> $key =><span> $value) { $data[$key] </span>= $<span>this</span>-><span>addSlashes($value); } } </span><span>else</span><span> { $data </span>=<span> addSlashes(trim($data)); } </span><span>return</span><span> $data; } </span><span>//</span><span>获取客户端IP</span> <span>public</span><span> function getClientIp() { </span><span>if</span>(!isset($<span>this</span>->e[<span>'</span><span>ip</span><span>'</span><span>])) { </span><span>if</span> (getenv(<span>"</span><span>HTTP_CLIENT_IP</span><span>"</span>) && strcasecmp(getenv(<span>"</span><span>HTTP_CLIENT_IP</span><span>"</span>), <span>"</span><span>unknown</span><span>"</span><span>)) $ip </span>= getenv(<span>"</span><span>HTTP_CLIENT_IP</span><span>"</span><span>); </span><span>else</span> <span>if</span> (getenv(<span>"</span><span>HTTP_X_FORWARDED_FOR</span><span>"</span>) && strcasecmp(getenv(<span>"</span><span>HTTP_X_FORWARDED_FOR</span><span>"</span>), <span>"</span><span>unknown</span><span>"</span><span>)) $ip </span>= getenv(<span>"</span><span>HTTP_X_FORWARDED_FOR</span><span>"</span><span>); </span><span>else</span> <span>if</span> (getenv(<span>"</span><span>REMOTE_ADDR</span><span>"</span>) && strcasecmp(getenv(<span>"</span><span>REMOTE_ADDR</span><span>"</span>), <span>"</span><span>unknown</span><span>"</span><span>)) $ip </span>= getenv(<span>"</span><span>REMOTE_ADDR</span><span>"</span><span>); </span><span>else</span> <span>if</span> (isset($_SERVER[<span>'</span><span>REMOTE_ADDR</span><span>'</span>]) && $_SERVER[<span>'</span><span>REMOTE_ADDR</span><span>'</span>] && strcasecmp($_SERVER[<span>'</span><span>REMOTE_ADDR</span><span>'</span>], <span>"</span><span>unknown</span><span>"</span><span>)) $ip </span>= $_SERVER[<span>'</span><span>REMOTE_ADDR</span><span>'</span><span>]; </span><span>else</span><span> $ip </span>= <span>"</span><span>unknown</span><span>"</span><span>; $</span><span>this</span>->e[<span>'</span><span>ip</span><span>'</span>] =<span> $ip; } </span><span>return</span> $<span>this</span>->e[<span>'</span><span>ip</span><span>'</span><span>]; } </span><span>//</span><span>根据二级域名获取信息</span> <span>public</span><span> function getSecondDomain() { $domain </span>= $_SERVER[<span>'</span><span>HTTP_HOST</span><span>'</span><span>]; $domain </span>= str_replace(array(<span>'</span><span>com.cn</span><span>'</span>,<span>'</span><span>net.cn</span><span>'</span>,<span>'</span><span>gov.cn</span><span>'</span>,<span>'</span><span>org.cn</span><span>'</span>),<span>'</span><span>com</span><span>'</span><span>,$domain); $tmp </span>= explode(<span>'</span><span>.</span><span>'</span><span>,$domain); </span><span>if</span>(count($tmp) < <span>3</span>)<span>return</span> <span>false</span><span>; elseif(is_numeric($tmp[</span><span>0</span>]))<span>return</span> <span>false</span><span>; </span><span>else</span> <span>return</span> $tmp[<span>0</span><span>]; } } </span>?>
声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章
如何修复KB5055612无法在Windows 10中安装?
1 个月前ByDDD
<🎜>:泡泡胶模拟器无穷大 - 如何获取和使用皇家钥匙
4 周前By尊渡假赌尊渡假赌尊渡假赌
<🎜>:种植花园 - 完整的突变指南
3 周前ByDDD
北端:融合系统,解释
4 周前By尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆树的耳语 - 如何解锁抓钩
3 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

Atom编辑器mac版下载
最流行的的开源编辑器

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

禅工作室 13.0.1
功能强大的PHP集成开发环境

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

Dreamweaver Mac版
视觉化网页开发工具