2013-05-12 117 views
0

我有一个php文件,它没有建立数据库连接。将URL作为参数传递时出现403错误

当我传递一个URL像

http://mydomain.com?q=http%3A%2F%2Fmyoranotherdomain.com 

设置了一个param它显示403错误:

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

当我删除在参数的HTTP的一部分,这是正常的像

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

如何让域名作为参数传递给网址?

回答

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?

答案是的东西,如更换http://www字符串:在JavaScript htpwwwashere和你的PHP再次更换它。 原因 - 根据上面的链接 - 是一些安全的东西,如防止注入攻击他们正在服务的网页。

+0

这个方法和JS编码URL有区别吗?我使用JavaScript编码参数 – 2013-05-12 21:34:23

+0

也许 - 什么是你的编码JS behinde – DominikAngerer 2013-05-12 21:35:22

+1

对于JavaScript使用'encodeURIComponent(字符串)' – Bart 2013-05-12 21:36:02