开发者

PHP removing backslash from code submitted through $_POST

I have a code editor block and and submitting code like the following:

$something = "<a href=\"somepage.html\">Link</a>";

However, when I submit it the string t开发者_C百科hat gets output is missing the backslash escape characters and I get:

$something = "<a href="somepage.html">Link</a>";

...which obviously isn't correct. I've figured out that it has to do with magic_quotes_gpc and when turned "On" works properly. My goal is for the application to be able to be installed easily on multiple hosts and I'd like to avoid having to turn on magic_quotes_gpc on every instance.


Link Here

Magic Quotes are depreciated and going to be removed in PHP6. If you still want your code to be portable, no warnings etc, as of PHP52 you can use the following code.

<?php
    foreach ($_GET as $key => &$val)
        $val = filter_input(INPUT_GET, $key);

    foreach ($_POST as $key => &$val)
        $val = filter_input(INPUT_POST, $key);
?>

The above will retrieve an-escaped GETs and POSTs regardless system settings. It can also be used for $_COOKIES and others.


Try double escaping:

$something = "<a href=\\"somepage.html\\">Link</a>";


The addslashes()-method might be what you're looking for.

However, if you want to directly put those values in a Database, you can use the mysql_real_escape_string()-method or you go with a Prepared Statement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜