JQuery向用户输入添加斜杠(textarea)

时间:2013-03-23 14:48:02

标签: php mysqli

我正在创建一个使用JQuery Post更新到数据库的用户配置文件,我刚刚注意到,如果我在textarea中使用了这个词,它就会无法上传到数据库并将其读回在个人资料上。我在php中的请求看起来像这样:

$name = mysqli_real_escape_string($con, $_REQUEST["name"]);
$location = mysqli_real_escape_string($con, $_REQUEST["location"]);
$about = mysqli_real_escape_string($con, $_REQUEST["about"]);

那么我可以添加什么来阻止添加斜杠吗?

1 个答案:

答案 0 :(得分:-1)

正如其他人在评论中已经说过的那样,都是因为魔术引用:

Disabling Magic Quotes - manual

如果您无法禁用它们并且不想更改代码,则可以在文件中插入此代码段。

  if (get_magic_quotes_gpc())
  {
    function stripslashes_gpc(&$value)
    {
      $value = stripslashes($value);
    }
    array_walk_recursive($_GET, 'stripslashes_gpc');
    array_walk_recursive($_POST, 'stripslashes_gpc');
    array_walk_recursive($_COOKIE, 'stripslashes_gpc');
    array_walk_recursive($_REQUEST, 'stripslashes_gpc');
  }
相关问题