PHP防止被xss和sql語句注入攻擊的方法(網站和app通用)
阿新 • • 發佈:2019-01-29
傳過來的引數 如果是整數型別 那就直接用intval函式轉化為整數 字串 那就要用函數了 注意輸入的內容htmlspecialchars過濾程式碼如下 // Anti_SQL Injection, escape quotes
function filter($content) { if (!get_magic_quotes_gpc()) { return addslashes($content); } else { return $content; } } //過濾引數防止xss攻擊 如果返回0 說明被攻擊 中斷執行 function filterStr($arr,$dec='') { $reivearr = trim($arr); if (!isset($arr)) { return null; } $arr = filter(stripSQLChars(stripHTML(trim($arr), true))); if ($reivearr != $arr) { echo json_encode(array('success' => 0, 'msg' => $dec.'含有非法字元')); exit(); } else { return $arr; } } function stripHTML($content, $xss = true) { $search = array("@
檢視原文:http://newmiracle.cn/?p=140