开发者

PHP $_GET apostrophe [duplicate]

This question already has answers here: 开发者_如何学Go Closed 12 years ago.

Possible Duplicate:

“slash before every quote” problem

Hi, I am trying to use $_GET to send the contents of a text box to another php document. But whenever I try to use single (') or double (") quotes, the text is received as \' or \". When I try to use str_replace, I get a php error. I need to use $_GET instead of $_POST, because I need to be able to bookmark the page.

Here is the code: HTML document:

<form action="result.php" method="get">
<input type="text" name="code" size="70" />
<input type="submit" />
</form>

PHP document:

<?php
echo $_GET["code"];
?>


Disable Magic Quotes. On top of the page, you can code like this:

<?php
if (get_magic_quotes_gpc()) {
    $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
    while (list($key, $val) = each($process)) {
        foreach ($val as $k => $v) {
            unset($process[$key][$k]);
            if (is_array($v)) {
                $process[$key][stripslashes($k)] = $v;
                $process[] = &$process[$key][stripslashes($k)];
            } else {
                $process[$key][stripslashes($k)] = stripslashes($v);
            }
        }
    }
    unset($process);
}
?>

There are better options available. REad here http://www.php.net/manual/en/security.magicquotes.disabling.php


Disable magic quotes on your server.

(unless you have something looping through the $_GET[] and using something like addslashes()).

You can tell if you have magic quotes enabled by running...

var_dump(get_magic_quotes_gpc());
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜