The best way to filter XSS depends on which platform you are running on. Regular expressions can be useful in preventing many types of vulnerabilities, but this is not always the best. The best way to prevent XSS in PHP is to use htmlspeicalchars();For example:
Reflective XSS:
print $_GET['xss'];
Corrected:
print htmlspecialchars($_GET['xss'],ENT_QUOTES);
To test this, we can try and execute some JavaScript.
http://127.0.0.1/xss.php?xss=<script>alert(/xss/)</script>
In the first example, we get a pop-up saying / xss /. The corrected example will display a safe version of the html string: <script> warning (/ XSS /) </script>
, < > , < > , XSS.