CodeIgniter -> Get current URL relative to base url

后端 未结 10 1133
情话喂你
情话喂你 2020-12-29 05:08

Tried URI::uri_string() but can\'t get it to work with the base_url.

URL: http://localhost/dropbox/derrek/shopredux/ahahaha/hihihi
Returns: dr

相关标签:
10条回答
  • 2020-12-29 05:46
     //if you want to get parameter from url use:
     parse_str($_SERVER['QUERY_STRING'], $_GET);
     //then you can use:
     if(isset($_GET["par"])){
          echo $_GET["par"];
     }
     //if you want to get current page url use:
     $current_url = current_url();
    
    0 讨论(0)
  • 2020-12-29 05:47

    I don't know if there is such a function, but with $this->uri->uri_to_assoc() you get an associative array from the $_GET parameters. With this, and the controller you are in, you know how the URL looks like. In you above URL this would mean you would be in the controller dropbox and the array would be something like this:

    array("derrek" => "shopredux", "ahahaha" => "hihihi");
    

    With this you should be able to make such a function on your own.

    0 讨论(0)
  • 2020-12-29 05:49

    If url helper is loaded, use

    current_url();
    

    will be better

    0 讨论(0)
  • 2020-12-29 05:50

    I see that this post is old. But in version CI v3 here is the answer:

    echo $this->uri->uri_string();
    

    Thanks

    0 讨论(0)
提交回复
热议问题