2013-03-06 170 views
8

我有一些問題通過URL的GET參數。當我嘗試訪問:如何使用PHP在URL中傳遞URL(作爲GET參數)?

http://www.linkebuy.com.br/linkebuy/parceiro?url=http%3A%2F%2Fwww.google.com

我得到以下信息:

Unexpected error.

但是,如果我去:

http://www.linkebuy.com.br/linkebuy/parceiro?url=123

一切工作就好了(當然,它會重定向到一個不存在的網站 - 123 - 但它確實如此)。通過消除,我可以說url參數有問題,但它是什麼?我想用rawurlencode()來編碼URL。

編輯:代碼你問...

的第一視圖,其中的鏈接是(http://www.linkebuy.com.br/notebook/detalhe?id=5):

<!-- url() function just completes the right URL (production or development) --> 
<a href="<?php echo url('linkebuy/parceiro/?url=' . rawurlencode($l->getUrl()), true) ?>" class="<?php echo $leadClass ?> oferta" target="_blank"> 
    <?php echo $l->getNomeFantasia() ?> 
</a> 

當點擊該鏈接重定向到一個動作(/linkebuy/parceiro ),發生以下情況(基本上什麼也沒有,只是保留在框架中):

public function execute($request, $response) { 
    $response->addParameter('url', rawurldecode($request->getParameter('url', ''))); //This creates $url in the view 
    $response->setTemplate('site/linkebuy/lead-parceiro.php'); //Forwards to the view 
} 

它包括視圖,lead-parceiro.php(以上關於這個問題,我和網頁鏈接),其中頭包括:

<script type="text/javascript"> 
    setInterval(function(){ window.location = '<?php echo $url ?>'; },3000); 
</script> 
+0

使用簡單'進行urlencode()'和告訴我們,如果有什麼差別。 – 2013-03-06 17:35:16

+0

沒有任何區別。 – ramonztro 2013-03-06 17:36:17

+2

問題出在您的重定向功能....向我們展示代碼;) – Hackerman 2013-03-06 17:37:01

回答

6

如果你無法擺脫的限制,你可以通過在2網址這樣的部分

http://www.linkebuy.com.br/linkebuy/parceiro?protocol=http&url=www.google.com 

然後解析它在您的代碼,以使重定向的完整url。

+0

YEAH!你是對的!我怎樣才能解決這個問題?我的意思是,修復apache配置。 – ramonztro 2013-03-06 18:10:52

+0

我不確定,這可能是一個重寫規則來檢查你的querystring。看看.htaccess文件和apache conf文件來找到它。 – Ateszki 2013-03-06 18:13:01

+2

看看這個答案,因爲你的網站是在hostgator,接受的答案必須是相關的http://stackoverflow.com/questions/10992219/http-in-query-string-does-not-work – Ateszki 2013-03-06 18:17:39

4

你應該使用urlencode當你通過什麼作爲URL參數