2013-05-12 52 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