Securing & Cleaning Strings in inputs like Login, etc.


/ Published in: PHP
Save to your folder(s)

By Eduardo de la Torre.


Copy this code and paste it in your HTML
  1. <?php
  2. // SECURE STRINGS IN LOGIN ETC.
  3. // By Eduardo de la Torre from www.atinamedia.com
  4.  
  5. function clean_string($string, $length){
  6. $string = substr($string, 0, $length);
  7. $string = strip_tags(trim($string));
  8. return $string;
  9. }
  10.  
  11. // Example:
  12. // If... Triying XSS
  13.  
  14. $foo = "<scrip>alert(\"ALARM!!\");</script>";
  15.  
  16. // The length is limit to 40 characters (for example)
  17. echo clean_string($foo, 40);
  18. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.