saving html content in mysql database

后端 未结 4 790
青春惊慌失措
青春惊慌失措 2021-01-07 09:33

I am using php and trying save some html contents in mysql database. the html content is generating by ckeditor. The content is something like this-



        
4条回答
  •  一整个雨季
    2021-01-07 10:24

    It sounds like your host probably has magic_quotes_gpc turned on, which will automatically add slashes to quotes and double quotes on data coming in from $_GET, $_POST, and $_COOKIE.

    You might want to create a wrapper function for escaping GPC data. As an example...

    function mysql_escape_gpc($dirty)
    {
        if (ini_get('magic_quotes_gpc'))
        {
            return $dirty;
        }
        else
        {
            return mysql_real_escape_string($dirty);
        }
    }
    

    This way your code is portable, regardless of how the server is configured.

    Also, if your production environment supports it, you should consider looking into prepared statements. This way you don't have to worry about escaping your data, however you would still need to UNescape it in the event that magic_quotes_gpc is turned on.

提交回复
热议问题