我正在检索$_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
知道是什么搞砸了吗?
不要对整个查询字符串进行编码。在您的代码中,您正在转换"?"answers"&"answers"="。
分别对值进行编码,并将值连接起来。
$query = "?user=" . urlencode($user) . "&password=" . urlencode($password);
最终,这也将允许您对它们进行消毒。
试试这个
<?php
$url= 'sendData.php?';
$url .= rawurlencode('user=somebody&password=any');
?>
只需要对查询字符串进行编码