您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

封装防sql注入的方法

2024/4/14 13:40:05发布13次查看
php代码
<?php /** * 批量实体转义 * @param $data * @return array|string */ function deepspecialchars($data) { if (empty($data)) { return $data; } return is_array($data) ? array_map("deepspecialchars", $data) : htmlspecialchars($data); } /** *批量单引号转义 * @param $data * @return array|string */ function deepslashes($data) { if (empty($data)) { return $data; } return is_array($data) ? array_map('deepslashes', $data) : addslashes($data); } //调用案例 $arr = array('username' => '张三<p></p>', 'age' => "18'#", 'desc' => '<script>alert("hello")</script>'); $arr = deepspecialchars($arr);//标签转义成实体 $arr = deepslashes($arr);//单引号转义 print_r($arr); //result /* array ( [username] => 张三&lt;p&gt;&lt;/p&gt; [age] => 18\'# [desc] => &lt;script&gt;alert(&quot;hello&quot;)&lt;/script&gt; ) */
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product