如何通过在URL网址(如GET参数)使用PHP? [英] How to pass URL in URL (as GET parameter) using PHP?

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

问题描述

我在传递URL作为GET参数的一些问题。当我尝试访问:

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

我得到以下信息:

但是,如果我去的:

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

一切都工作得很好(它重定向到一个不存在的网站 - 123 - 当然,但它的预期)。通过消除我可以说有什么毛病网​​址参数,但它是什么?

OBS:我用 rawurlen code()为en code中的网址

编辑: code你问...

在第一种观点,这里的链接( HTTP:// WWW。 linkebuy.com.br/notebook/detalhe?id=5 ):

 <! -  URL()函数只是完成正确的URL(生产或开发) -  GT;
< A HREF =<?PHP的回声URL('?linkebuy / parceiro / URL ='rawurlen code($ 1→的getURL()),TRUE)>? CLASS =< PHP的echo $ leadClass> oferta目标=_空白>
    <?PHP的echo $ 1→?getNomeFantasia()>
&所述; / A>

当点击该链接重定向到一个动作( / linkebuy / parceiro ),其中发生以下(basicly什么,只是在框架中保持):

 公共职能执行($请求,响应$){
    $响应 - > addParameter(URL,rawurlde code($请求 - >的getParameter('URL',''))); //这个视图创建$网址
    $响应 - > setTemplate('网站/ linkebuy /铅parceiro.php'); //转发到视图
}

它包括视图,铅parceiro.php (上面的问题,我和网页链接),其中包含了头:

 <脚本类型=文/ JavaScript的>
    的setInterval(函数(){了window.location ='< PHP的echo $网址>';},3000);
< / SCRIPT>


解决方案

如果您无法摆脱的限制,你可以通过URL两部分像这样

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

,然后分析它在你的code,以便为重定向的完整URL。

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.

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

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