如何使用 PHP 在 URL 中传递 URL(作为 GET 参数)? [英] How to pass URL in URL (as GET parameter) using PHP?

查看:66
本文介绍了如何使用 PHP 在 URL 中传递 URL(作为 GET 参数)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将 URL 作为 GET 参数传递时遇到了一些问题.当我尝试访问时:

一切正常(它重定向到一个不存在的站点 - 123 - 当然,但它符合预期).通过消除,我可以说 url 参数有问题,但它是什么?

OBS:我使用 rawurlencode() 对 URL 进行编码.

你问的代码...

在第一个视图中,链接在哪里 (http://www.linkebuy.com.br/notebook/detalhe?id=5):

<!-- url() 函数只是完成正确的 URL(生产或开发)--><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', '')));//这会在视图中创建 $url$response->setTemplate('site/linkebuy/lead-parceiro.php');//转发到视图}

它包括视图,lead-parceiro.php(上面的问题,我链接到这个页面),头部包含:

解决方案

如果你不能摆脱限制,你可以像这样分两部分传递 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.

这篇关于如何使用 PHP 在 URL 中传递 URL(作为 GET 参数)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆