ThinkPHP提交表单时默认自动转义的解决方法,thinkphp转义
本文实例讲述了ThinkPHP提交表单时默认自动转义的解决方法。分享给大家供大家参考。具体方法如下:
一、问题:
在ThinkPHP中提交表单插入数据的时候,单引号和双引号是会被自动转义的,就是会自动的加上反斜线,但是我不想给单引号和双引号加上反斜线.
在ThinkPHP中提交表单插入数据的时候,单引号和双引号是会被自动转义的,就是会自动的加上反斜线,但是我不想给单引号和双引号加上反斜线,在ThinkPHP中提交表单插入数据的时候,单引号和双引号是会被自动转义的,就是会自动的加上反斜线,但是我不想给单引号和双引号加上反斜线,如:hds"gh"j'g'h 会被自动转义为:hds\"gh\"j\'g\'h.
请注意需要的是取消这个转义的功能,而不是使用stripslashes() 函数删除这些反斜杠,即不需要官方的这个自动转义的功能.
二、解决方法:
在网上搜索到解决方法:
1、在thinkphp目录下,依次打开 ThinkPHP\Lib\Driver\Db 目录,并在dbmysql.class.php 这个文件中把 escapeString 函数的函数修改成:
复制代码 代码如下:
public function escapeString($str) {
//修改 周蛮子 放双引号双重转义
if (!get_magic_quotes_gpc()){
if($this->_linkID) {
return mysql_real_escape_string($str,$this->_linkID);
}else{
return mysql_escape_string($str);
}
} else {
return $str;
}
}
原函数:
复制代码 代码如下:
public function escapeString($str) {
//修改 周蛮子 放双引号双重转义
if($this->_linkID) {
return mysql_real_escape_string($str,$this->_linkID);
}else{
return mysql_escape_string($str);
}
}
2、在公共文件中加入:
复制代码 代码如下:
//防止双重转义
if (get_magic_quotes_gpc()) {
function stripslashes_deep($value){
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}
注:如果服务器开了转义,那么就经过thinkphp再次转义后,就会在程序中产生双重转义的Bug
经过修改后,我的网站程序后台录入就没什么问题了,看来大家以后如果有碰到使用Thinkphp时,注意如果服务器开启了过滤单引号或双引号的,可能就会跟ThinkPHP起冲突的了,所以加一层判断,就可以很好的解决这个问题了.
希望本文所述对大家的ThinkPHP框架程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.