Home  >  Article  >  Backend Development  >  php通过格式化数据以防止注入的函数

php通过格式化数据以防止注入的函数

WBOY
WBOYOriginal
2016-07-25 09:03:45879browse
  1. //格式化数据(防止注入)
  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. ?>
复制代码

除了以上的方法,建议大家参考下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 [email protected]