PHP urlencode 和解码

发布于 2024-08-21 01:03:18 字数 516 浏览 4 评论 0原文

所有,

有一个文本区域说

 <input type="submit">

如果用户输入为,

 here is my name  and my mail id is "[email protected]" 

并且当数据发布到服务器端时,数据将被接收为 这是我的名字,我的邮件 ID 是 \"[电子邮件受保护]\ "

在双引号后面添加反斜杠。现在如何在提交之前对数据进行编码。我在服务器端使用 php..

谢谢。

All,

There is a text area say

 <input type="submit">

And if a user gives the input as,

 here is my name  and my mail id is "[email protected]" 

And when the data is posted on the server side the data is received as
here is my name and my mail id is \"[email protected]\"

Backslash is added behind double quotes.Now how to encode the the data before submitting.I am using php on the server side..

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

情释 2024-08-28 01:03:18

这是 magic_quotes_gpc 的作用 - 要删除它只需在 php.ini 中禁用它或使用 stripslashes($your_var) 删除它;

尽管请记住,这是 php 的一个(糟糕的)安全功能,但是当将数据存储到数据库时,您应该使用相应的转义函数来防止 sql 注入,并且当显示用户发布的数据时,您的清理函数应该防止 xss 注入。

this is magic_quotes_gpc kicking in - to remove it just disable it in php.ini or remove it using stripslashes($your_var);

though bear in mind that this is a (lousy) security feature of php, but when storing the data to a database you should use the respective escape functions to prevent sql injections anyway and when showing user-posted data your sanitizing function should prevent xss injections.

℉絮湮 2024-08-28 01:03:18

它看起来像指令 magic_quote_gpc< /code>在您的服务器上启用:

当 magic_quotes 打开时,所有 '
(单引号), " (双引号),
(反斜杠)和 NUL 被转义
自动反斜杠。

A solution, if you can't disable it in your server's configuration, would be to :

关于这一点,您可以阅读 部分禁用魔术引号

Of course, you'll have to escape your data properly before using it ; for instance, before injecting it into an SQL query.

It looks like the directive magic_quote_gpc is enabled on your server :

When magic_quotes are on, all '
(single-quote), " (double quote),
(backslash) and NUL's are escaped with
a backslash automatically.

A solution, if you can't disable it in your server's configuration, would be to :

  • detect if this is enabled
  • if yes, remove the escaping from the input, using stripslashes

About that, you can read the section Disabling Magic Quotes.

Of course, you'll have to escape your data properly before using it ; for instance, before injecting it into an SQL query.

花开雨落又逢春i 2024-08-28 01:03:18

如果您的网络托管提供商不允许您在 php.ini 文件中禁用它,您也可以在 PHP 中删除魔术引号。将此代码放在 PHP 脚本之上:

    if (get_magic_quotes_gpc()) {
        function stripslashes_deep($value) {
            $value = is_array($value) ?
                     array_map('stripslashes_deep', $value) :
                     stripslashes($value);
            return $value;
        }

        $_POST = array_map('stripslashes_deep', $_POST);
        $_GET = array_map('stripslashes_deep', $_GET);
        $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
        $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
    }

You can get rid of magic quotes also in PHP if your web hosting provider doesn't allow you to disable it in php.ini file. Put this code on top of your PHP script:

    if (get_magic_quotes_gpc()) {
        function stripslashes_deep($value) {
            $value = is_array($value) ?
                     array_map('stripslashes_deep', $value) :
                     stripslashes($value);
            return $value;
        }

        $_POST = array_map('stripslashes_deep', $_POST);
        $_GET = array_map('stripslashes_deep', $_GET);
        $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
        $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
    }
苦妄 2024-08-28 01:03:18

在 php.ini 中禁用 magic_quotes 或在 PHP 中使用 stripslashes($text) 来删除斜杠。

Disable magic_quotes in php.ini or use stripslashes($text) in PHP to remove slashes.

中二柚 2024-08-28 01:03:18

您的系统上可能启用了魔术引号。这不是一件好事

You probably have magic quotes enabled on your system. This is not a good thing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文