将url作为参数传递时出现403错误

时间:2013-05-12 21:26:06

标签: php http-status-code-403 url-parameters

我有一个不建立数据库连接的php文件。

当我传递网址作为

之类的参数时
 http://mydomain.com?q=http%3A%2F%2Fmyoranotherdomain.com

显示403错误:

 You don't have permision to access blahblah.php file.

当我删除param中的http部分时,它就像

一样
 http://mydomain.com?q=myoranotherdomain.com

如何让域名作为params在域名中传递?

1 个答案:

答案 0 :(得分:0)

最简单的方法是使用以下代码对网址进行编码:

string urlencode ( string $str )

http://php.net/manual/en/function.urlencode.php

您还必须进行解码:

string urldecode ( string $str )

http://php.net/manual/en/function.urldecode.php

使用特殊字符对参数进行编码总是这个方法。

最终解决方案:

我发现了这个:I get a 403 error when submitting "http://www." via GET. Even if it's encoded beforehand. Is there a solution for this?

答案是在javascript中将http://www String替换为:htpwwwashere,并在php中再次替换它。 原因 - 根据上面的链接 - 是一些安全的东西,比如防止他们正在服务的页面上的注射攻击。