【问题标题】:How to pass URL in URL (as GET parameter) using PHP?如何使用 PHP 在 URL 中传递 URL(作为 GET 参数)?
【发布时间】:2013-02-21 15:26:19
【问题描述】:

我在将 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 - 当然,但它符合预期)。通过排除,我可以说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>

【问题讨论】:

  • 使用简单的urlencode() 并告诉我们这是否有任何不同。
  • 完全没有区别。
  • 问题出在您的重定向功能中......向我们展示代码;)
  • http%3A%2F%2Fgoogle.com 是 urlencoded
  • 我认为可能是 apache 配置限制不允许在您的查询字符串中包含 http://

标签: php apache url parameters get


【解决方案1】:

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

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

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

【讨论】:

  • 是的!你说得对!我怎样才能解决这个问题?我的意思是,修复 apache 配置。
  • 我不确定,这可能是检查您的查询字符串的重写规则。查看 .htaccess 文件和 apache conf 文件以找到它。
  • 看看这个答案,因为你的网站在hostgator,接受的答案必须是相关的stackoverflow.com/questions/10992219/…
  • 对于那些正在寻找替代答案的人,您可以base64_encode URL 和base64_decode 稍后。
【解决方案2】:

当您将任何内容作为 URL 参数传递时,您应该使用 urlencode

【讨论】:

    猜你喜欢
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 2012-09-05
    • 2017-08-17
    • 2011-02-09
    • 1970-01-01
    相关资源
    最近更新 更多