【问题标题】:Codeigniter url redirecting from address urlCodeigniter url 从地址 url 重定向
【发布时间】:2014-07-31 13:04:08
【问题描述】:

我的 codeigniter 有问题,我找不到解决方法。

如何在不将 / 解释为控制器模型等之间的分隔符的情况下将目标 url 解析为 url 来进行重定向。

例如:

http://www.example.com/http://www.google.com/?q=test

应该做什么将http://www.google.com/?q=test作为字符串放入

Header("Location: http://www.google.com/?q=test");

有什么想法吗?

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    您可以使用 url 助手的重定向功能。如果你给它一个完整的地址(带有 http://),它会重定向到那个外部 url。 https://ellislab.com/codeigniter/user-guide/helpers/url_helper.html

    【讨论】:

    • 不,这对我没有帮助,因为我尝试从外部来源进行重定向,就像外部链接跟踪器一样,并将访问的网站和访问该链接的 ip 存储到 mysql 中。 url helper 唯一的帮助是变量在文件中而不是在 $_REQUEST ...
    【解决方案2】:
    redirect("controller_name/function_name");
    

    此代码使用 header function in php

    相当于base_url() + redirect value

    【讨论】:

      【解决方案3】:

      我成功了,

      我使用 url 库,就像有 sugest Juul,代码就像(在控制器中):

      class url extends CI_Controller { 
          function index() {
              # the codeigniter not accept the characters after ? and i make a custom code 
              # to know where is the ? sign and then i replace http:/ whith two // 
      
              $url = str_replace(":/","://",str_replace('%5E','?',$this->uri->uri_string));
      
              #the url var will return http://www.google.com/?q=test
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2014-06-19
        • 1970-01-01
        • 1970-01-01
        • 2014-11-30
        • 2012-12-23
        • 2015-11-12
        • 2013-04-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多