Your Ad Here

Posted By

jschilling on 06/10/09


Tagged

ajax php sanitize


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

brent-man
vali29
aleksanderek


cleanData


 / Published in: PHP
 

URL: http://www.six-degrees.com/six-degrees.html

Feel free to use any way you want. This function will take user submitted data and make sure it is free of XSS attacks and also decode Ajax submitted data if the flag is set to true, now with a conditional check for magic quotes.

  1. function cleanData($data, $isUrlEncoded=FALSE) {
  2. if( function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() ) {
  3. $data = stripslashes($data);
  4. }
  5. if( is_string($data) ) {
  6. return ($isUrlEncoded) ?
  7. strip_tags(trim($data));
  8. }
  9. else {
  10. return ($isUrlEncoded) ?
  11. urldecode($data) :
  12. $data;
  13. }
  14.  
  15. };

Report this snippet  

You need to login to post a comment.