There are two backslashes and thinkphp Database Class escape characters in the thinkphp database.

Source: Internet
Author: User

This occurs when magic_quotes_gpc is enabled. The reason is that thinkphp does not judge whether magic_quotes_gpc is enabled when it comes to the database, regardless of the escape processing in November 21.

The solution is to add the following code to the entry file:

if (!get_magic_quotes_gpc()) {    function addslashes_deep($value) {         $value = is_array($value) ?            array_map('addslashes_deep', $value) :            addslashes($value);        return $value;   }   $_POST = array_map('addslashes_deep', $_POST);   $_GET = array_map('addslashes_deep', $_GET);   $_COOKIE = array_map('addslashes_deep', $_COOKIE);   $_REQUEST = array_map('addslashes_deep', $_REQUEST);}

Someone modified the escape Function in dbmysql. Class. php as follows:

public function escape_string($str) {if (get_magic_quotes_gpc()) {return $str;}if($this->_linkID) {return mysql_real_escape_string($str,$this->_linkID);}else{return mysql_escape_string($str);}}

This method is not available! Because if the magic function on, and $ STR is not post or get (such as reading text or database), it still does not add a backslash.
Therefore, no matter whether $ STR has been escaped or not, I will first remove the escape and then add the escape. This avoids the second escape and the omission escape.
The following is my modification method:

public function escape_string($str) {$str = stripslashes($str);if($this->_linkID) {return mysql_real_escape_string($str,$this->_linkID);}else{return mysql_escape_string($str);}}

Article Source: http://www.thinkcart.net/thinkphp-escape-string-110.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.