<? php/*** @blog http://www.phpddt.com* @param $string * @param $low safety level low */function CLEAN_XSS (& $string, $low = False) { if (! Is_array ($string)) {$string = Trim ($string); $string = Strip_tags ($string); $string = Htmlspecialchars ($string); if ($low) {return True; } $string = Str_replace (Array (' "'," \ \ "," ' ","/"," ... "," ... /","./","//"),", $string); $no = '/%0[0-8bcef]/'; $string = Preg_replace ($no, ", $string); $no = '/%1[0-9a-f]/'; $string = Preg_replace ($no, ", $string); $no = '/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]+/s '; $string = Preg_replace ($no, ", $string); return True; } $keys = Array_keys ($string); foreach ($keys as $key) {CLEAN_XSS ($string [$key]); }}//just a test$str = "<script>alert (document.cookie) </script>"; Clean_xss ($STR); If you leave this comment off, you know that the XSS attack is powerful. Echo $str;
PHP-Prevent XSS (cross-site scripting attacks)