【问题标题】:php POST data retrieving issuephp POST数据检索问题
【发布时间】:2011-12-10 10:26:13
【问题描述】:

我正在从以下链接的页面上的 $_GET 检索数据:

<a class="send" href="<?php echo sendData.php?user=somebody&password=any; ?>">Send POST info</a>

在本地使用 XAMPP 和

            <?php
                $user = urlencode($_GET['user']);
                $password = urlencode($_GET['password']);
                echo '<strong>user: </strong>'.$user.' <strong>password: </strong>'.$password;                
            ?>

它工作正常,但是在编码时

        <?php
            $url=rawurlencode('sendData.php');
            $url .= urlencode('?user=somebody&password=any');
        ?>
        <a class="send" href="<?php echo $url; ?>">

             Send POST info
        </a>

链接页面被禁止访问

Access forbidden!

You don't have permission to access the requested object. It is either read-protected or not readable by the server.

If you think this is a server error, please contact the webmaster.

Error 403

localhost
18.10.2011 ã. 23:00:31 ÷.
Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1

有什么想法吗?

【问题讨论】:

    标签: php apache xampp localhost


    【解决方案1】:

    不要编码整个查询字符串。 在您的代码中,您正在转换“?”和“&”和“=”。

    单独编码这些值,然后连接这些值。

    所以

    $query = "?user=" . urlencode($user) . "&password=" . urlencode($password);
    

    最终,您也可以对它们进行消毒。

    【讨论】:

    • 是的,如果你查看源代码,你会在文件中看到&lt;a class="send" href="sendData.php%3Fuser%3Dsomebody%26password%3Dany"&gt;,因为你正在编码你不需要的东西,正如 Norguard 所说。此外,一旦您收到回复,就无需urlencode($_GET['user'])。如果要对其进行编码以进行输出,则无论如何都可以使用 htmlspecialchars($_GET['user']) 之类的东西。
    【解决方案2】:

    试试这个

    <?php
            $url= 'sendData.php?';
            $url .= rawurlencode('user=somebody&password=any');
        ?>
    

    只需要对查询字符串进行编码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多