Home  >  Article  >  Backend Development  >  PHP function that formats data to prevent injection

PHP function that formats data to prevent injection

WBOY
WBOYOriginal
2016-07-25 09:03:45998browse
  1. //Format data (prevent injection)
  2. function site_addslashes($string, $force = 0) {
  3. !defined('MAGIC_QUOTES_GPC') && define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc()) ;
  4. if(!MAGIC_QUOTES_GPC || $force) {
  5. if(is_array($string)) {
  6. foreach($string as $key => $val) {
  7. $string[$key] = daddslashes($val, $force);
  8. }
  9. } else {
  10. $string = addslashes($string);
  11. }
  12. }
  13. return $string;
  14. }
  15. ?>
Copy code

In addition to the above methods, it is recommended that everyone Refer to the anti-injection function of discuz.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn