PHP Anti-injection Code (filter parameters)

Source: Internet
Author: User
PHP filters $_get and $_post parameters to prevent injected code, there are friends in need, can refer to below.

The complete code is as follows.

     $value) {if (!is_array ($value)) {$value = GET_MAGIC_QUOTES_GPC ()? $value: Addslashes ($value); $array [$key]=filterhtml ( $value);} else{add_s ($array [$key]);} return $array;} function Glstr ($var) {if (Is_array ($var)) {return add_s ($var);} ElseIf (strlen ($var)) {$var = GET_MAGIC_QUOTES_GPC ()? $var: Addslashes ($var); $var = filterhtml ($var);} return $var;} function filterhtml ($html) {$farr = Array ("/]*?) >/eis ","/< (\?) (Html|body|head|link|meta|base|input) ([^>]*?) >/eis ","/< (Script|i?frame|style|title|form) (. *?) <\/\\1>/eis ","/(<[^>]*?\s+) on[a-z]+\s*?= (\ "|") ([^\\2]*) \\2 ([^>]*?>)/isu ",//filter on the JavaScript on event"/\s+/",//filter extra blanks); $tarr = Array (" "," "" "" "," \\1\\4 "," ","); $ html = preg_replace ($farr, $tarr, $html); return $html;} if (sizeof ($_get)) {foreach ($_get as $key = $value) {$_get[$key] = glstr ($value);//}}if (sizeof ($_post)) {foreach $_p OST as $key = $value) {$_post[$key] = glstr ($value);//}}?>
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.