如何使用PHP在URL中传递URL(作为GET参数)?

时间:2013-03-06 17:32:24

标签: php apache url parameters get

我在将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参数有问题,但它是什么?

OBS:我正在使用rawurlencode()对网址进行编码。

编辑: 您问的代码......

在第一个视图中,链接为(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>

2 个答案:

答案 0 :(得分:6)

如果你无法摆脱限制,你可以通过2个部分传递网址

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

然后在您的代码上解析它以生成重定向的完整URL。

答案 1 :(得分:5)

当您将任何内容作为网址参数

传递时,您应该使用urlencode
相关问题