转义引号的函数无法正常工作
我试图找出为什么这个功能不能正常工作。
每次我编辑条目时,它都会添加一个额外的 \
。
在线服务器具有以下设置:
magic_quotes_gpc On
magic_quotes_runtime Off
magic_quotes_sybase Off
这是代码:
function esc($s)
{
if (get_magic_quotes_gpc()) {
if (ini_get('magic_quotes_sybase'))
$s = str_replace("''", "'", $s);
else
$s = stripslashes($s);
} //if
return mysql_real_escape_string($s);
}
编辑说明:
我尝试完全删除此功能以查看它的作用......并且它做了同样的事情,所以我意识到addslashes
也在代码中用于同样的事情。
额外的 \
之所以存在,是因为 magic_quote
处于 ON
I'm trying to figure out why this function does not work correctly.
It's adding an extra \
every time I edit my entries.
Online server has these settings:
magic_quotes_gpc On
magic_quotes_runtime Off
magic_quotes_sybase Off
Here is the code:
function esc($s)
{
if (get_magic_quotes_gpc()) {
if (ini_get('magic_quotes_sybase'))
$s = str_replace("''", "'", $s);
else
$s = stripslashes($s);
} //if
return mysql_real_escape_string($s);
}
Edit note:
I have tried completely removing this function to see what it does... and it does the same thing, so I have realized that addslashes
is also use in the code for the same thing.
The extra \
were there because magic_quote
was ON
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的功能没有什么意义。如果启用了魔术引号(例如,输入被转义),则您将取消转义它。如果它没有打开,你就逃避它。因此,您会得到不同的结果,具体取决于您是否启用了魔术引用。
无论如何,依赖魔术引号是一种非常糟糕的做法。您应该:
Your function makes little sense. If magic quotes is on (eg. input is escaped), you unescape it. If it's not on, you escape it. So you'll get different results, depending on if you have magic quote on or not.
In any case, relying on magic quotes is a really bad practice. You should:
即使 magic_quotes_sybase 打开,您可能
也想去掉斜杠:您可能还想看看 PHP 的 get_magic_quotes_gpc功能页面上,页面上有几个用户评论,其中提供了相当优雅的解决方案,以确保删除斜杠。
You probably want to stripslashes even if magic_quotes_sybase is on:
You might also want to take a look at PHP's get_magic_quotes_gpc function page, there are several user comments on the page with fairly elegant solutions for ensuring slashes are stripped.
好的,我已经解决了问题。目前的快速解决方案是,我删除了
function esc($s)
。我在 php.ini 中将
Magic_Quote
更改为 OFF。我保留了addslashes 解决方案。
Ok I have fixed the problem. A quick solution for now, I have removed
function esc($s)
.I changed
Magic_Quote
to OFF in php.ini.I'm keeping addslashes solution.