Posted By

paulgrenwood on 09/30/09


Tagged

php forms


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

dharmastyle


Cleaning Variables


 / Published in: PHP
 

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.

  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  

You need to login to post a comment.