要看php.ini中的magic_quotes_gpc = off是不是打开了, 打开的时候,php会自动给你addslashes, 这样插入数据库的时候就不是手动的add了,但是在做一些判断的时候,就要去掉自动加的slashes.

解决方案 »

  1.   

    看程序是要注意上下文和程序运行的环境
    在默认配置中
    magic_quotes_gpc = on ;对传递数据转义
    magic_quotes_runtime = off ;对数据库和文件数据不转义当配置为
    magic_quotes_gpc = on ;对传递数据转义
    magic_quotes_runtime = on ;对数据库和文件数据转义
    时,入库前就要做stripslashes了。否则两次转义就出问题了因此,在程序中是否做addslashes和stripslashes要根据配置决定。
    你可以通过这两个函数来决定操作
    get_magic_quotes_gpc
    get_magic_quotes_runtime
      

  2.   

    也就是说如果以上配置中只要有一个为开,就得进行strip,否则就要add是否?
      

  3.   

    magic_quotes_gpc = off
    magic_quotes_runtime = off
    入库是要addslashesmagic_quotes_gpc = on
    magic_quotes_runtime = off
    入库是不要addslashes,假如没有做stripslashesmagic_quotes_gpc = off
    magic_quotes_runtime = on
    入库是不要addslashesmagic_quotes_gpc = on
    magic_quotes_runtime = on
    入库是要stripslashes
      

  4.   

    是的,我是把'替换成´,就需要先strip掉\.我也是这样用的,插入前处理str_replace("'","´",stripslashes($string));
      

  5.   

    我没判断过,直接addslashes...出来时再还原一下,好像也没出过什么问题
      

  6.   

    楼上如果你程序放到别人服务器下有时会有问题的。
    每次提交时判断下。
    if( !get_magic_quotes_gpc() )
    {
    if( is_array($HTTP_GET_VARS) )
    {
    while( list($k, $v) = each($HTTP_GET_VARS) )
    {
    if( is_array($HTTP_GET_VARS[$k]) )
    {
    while( list($k2, $v2) = each($HTTP_GET_VARS[$k]) )
    {
    $HTTP_GET_VARS[$k][$k2] = addslashes($v2);
    }
    @reset($HTTP_GET_VARS[$k]);
    }
    else
    {
    $HTTP_GET_VARS[$k] = addslashes($v);
    }
    }
    @reset($HTTP_GET_VARS);
    } if( is_array($HTTP_POST_VARS) )
    {
    while( list($k, $v) = each($HTTP_POST_VARS) )
    {
    if( is_array($HTTP_POST_VARS[$k]) )
    {
    while( list($k2, $v2) = each($HTTP_POST_VARS[$k]) )
    {
    $HTTP_POST_VARS[$k][$k2] = addslashes($v2);
    }
    @reset($HTTP_POST_VARS[$k]);
    }
    else
    {
    $HTTP_POST_VARS[$k] = addslashes($v);
    }
    }
    @reset($HTTP_POST_VARS);
    } if( is_array($HTTP_COOKIE_VARS) )
    {
    while( list($k, $v) = each($HTTP_COOKIE_VARS) )
    {
    if( is_array($HTTP_COOKIE_VARS[$k]) )
    {
    while( list($k2, $v2) = each($HTTP_COOKIE_VARS[$k]) )
    {
    $HTTP_COOKIE_VARS[$k][$k2] = addslashes($v2);
    }
    @reset($HTTP_COOKIE_VARS[$k]);
    }
    else
    {
    $HTTP_COOKIE_VARS[$k] = addslashes($v);
    }
    }
    @reset($HTTP_COOKIE_VARS);
    }
    }
      

  7.   

    楼上,你没有判定magic_quotes_runtime 呀。