code_junkie

taking care of XSS

Nov 13th, 2011
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. echo htmlentities($_POST[‘input’], ENT_QUOTES, ‘UTF-8’);
  2.  
  3. array_walk($_POST, 'htmlentities');
  4.  
  5. function h($s) { echo(htmlspecialchars($s)); }
  6. ...
  7. <?php h($POST['input']) ?>
  8.  
  9. $_POST = clean_input($_POST);
  10. $_GET = clean_input($_GET);
  11. $_COOKIE = clean_input($_COOKIE);
  12. $_SESSION = clean_input($_SESSION);
  13.  
  14. function clean_input($array){
  15. if(count($array)){
  16. foreach ($array as $key => $value) {
  17. $array[$key]=htmlentities($value, ENT_QUOTES, 'UTF-8');
  18. }
  19. }
  20. return $array;
  21. }
Add Comment
Please, Sign In to add comment