Cleaning Variables


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

Variables that are submitted via web forms always need to be cleaned/sanitized before use in any way, to prevent against all kinds of different malicious intent.


Copy this code and paste it in your HTML
  1. function clean($value) {
  2. // If magic quotes not turned on add slashes.
  3.  
  4. // Adds the slashes.
  5. { $value = addslashes($value); }
  6.  
  7. // Strip any tags from the value.
  8. $value = strip_tags($value);
  9.  
  10. // Return the value out of the function.
  11. return $value;
  12. }
  13.  
  14. $sample = "<a href='#'>test</a>";
  15. $sample = clean($sample);
  16. echo $sample;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.