且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-23 22:28:59

如果你不能摆脱限制,你可以像这样分两部分传递 url

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

然后在您的代码中解析它以制作重定向的完整网址.

I'm having some problems passing URL's as GET parameter. When I try to access:

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

I get the following message:

However, if I go for:

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

Everything works just fine (it redirects to an inexistent site - 123 -, of course, but it does the expected). By elimination I can say there's something wrong with the url parameter, but what is it?

OBS: I'm using rawurlencode() to encode the URL.

EDIT: Code you asked...

In the first view, where the link is (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>

When clicked the link redirects to an action (/linkebuy/parceiro), where happens the following (basicly nothing, just keeping in the framework):

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
}

It includes the view, lead-parceiro.php (above on the question, I link to this page), where the head contains:

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

If you can't get rid of the restriction you can pass the url in 2 parts like this

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

And then parse it on your code to make the full url for the redirect.