简体   繁体   English

如何摆脱PHP Mysql Ajax中的转义字符

[英]How to get rid of escape characters in PHP Mysql Ajax

I am trying to send a HTML code (variable target ) through AJAX request by escape(target) , but before entering it into database i am encoding it again by following, 我试图发送一个HTML代码(可变target通过) AJAX请求,由escape(target) ,但进入入数据库之前,我对下面的编码再次它,

$post=target recieved on PHP page by POST
$post= htmlentities($_POST['posttext']);
$post = mysql_real_escape_string($post);

Now while reading it back from MySql, i am using html_entity_decode($post) to post the desired output. 现在,当从MySql读取它时,我正在使用html_entity_decode($post)发布所需的输出。

PROBLEM: 问题:

On my local apache server everything is working fine but when i uploaded same code to online server, Few special characters of output are followed by \\ . 在我的本地apache服务器上,一切正常,但是当我将相同的代码上传到在线服务器时,输出的几个特殊字符后跟\\

EG. 例如。

On my local server. 在我的本地服务器上。

awk '/<ca>/{f=1;next}/<\/ca>/{f=0}f' $filename > ca.crt
awk '/<cert>/{f=1;next}/<\/cert>/{f=0}f' $filename > client.crt
awk '/<key>/{f=1;next}/<\/key>/{f=0}f' $filename > client.key

On online server. 在联机服务器上。

awk \'/<ca>/{f=1;next}/<\\/ca>/{f=0}f\' $filename > ca.crt
awk \'/<cert>/{f=1;next}/<\\/cert>/{f=0}f\' $filename > client.crt
awk \'/<key>/{f=1;next}/<\\/key>/{f=0}f\' $filename > client.key

Am i missing something? 我想念什么吗? Any Help? 有帮助吗?

Don't encode html entities just for database insertion, especially if you're just going to decode them again each time anyways. 不要只为插入数据库而对html实体进行编码,尤其是如果您每次都打算再次对其进行解码时。 waste of cpu cycles, and does NOTHING to protect against sql injection. 浪费cpu周期,并且无所不能以防止sql注入。

Your online server probably has magic_quotes enabled, which means it's either badly configured, or badly out-dated. 您的在线服务器可能启用了magic_quotes ,这意味着它的配置错误或过时。 magic_quotes will auto-escape quotes in any input to PHP, on the moronic assumption that no one could ever possibly want to send something to PHP and then NOT put it into the database. magic_quotes的会自动转义引号任何输入到PHP,在鲁钝的假设,没有人能永远不可能想送点东西给PHP,然后不要把它存入数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM