首页 > 开发 > PHP > 正文

php中stripslashes与 addslashes应用实例

2024-05-04 21:59:19
字体:
来源:转载
供稿:网友

首先测试 magic_quotes_gpc 是否为 ON,如果是,则用 array_map() 递归还原转义的数据,是否开启了自动addslashes功能只要我们在php.ini里看一就KO了或用get_magic_quotes_gpc()函数来检测,代码如下:

  1. <?php  
  2. // 说明: 用 stripslashes 还原 addslashes 转义后的数据 
  3. if(get_magic_quotes_gpc())  
  4. {  
  5.     function stripslashes_deep($value)  
  6.     {  
  7.         $value = is_array($value) ? array_map('stripslashes_deep'$value) : (isset($value) ? stripslashes($value) : null);  
  8.         return $value//开源软件:Vevb.com 
  9.     }  
  10.    
  11.     $_POST = stripslashes_deep($_POST);  
  12.     $_GET = stripslashes_deep($_GET);  
  13.     $_COOKIE = stripslashes_deep($_COOKIE);  
  14. }  
  15. ?>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表