ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Get Current URL

March 17, 2008 10:57pm

Subscribe [11]
  • #16 / Sep 01, 2011 11:27pm

    ashily

    1 posts

    I don’t think you need codeigniter to get current url, you could just use:

    <?= $_SERVER['REQUEST_URI'] ?>

    Thank you very much.

  • #17 / Sep 02, 2011 4:14am

    guillemsola

    2 posts

    I don’t think you need codeigniter to get current url, you could just use:

    <?= $_SERVER['REQUEST_URI'] ?>

    Thank you very much.

    The idea behind current_url is that it returns the full URL. From PHP manual

    'REQUEST_URI'
    
    The URI which was given in order to access this page; for instance, '/index.html'.

    current_url in CI

    function current_url()
    {
        $CI =& get_instance();
        return $CI->config->site_url($CI->uri->uri_string());
    }
  • #18 / Oct 18, 2011 10:26am

    franboud

    5 posts

    $ci->uri->uri_string();

    Thanks a lot for this tip!! It’s really useful for me.
    Thanks again 😊

  • #19 / Apr 28, 2012 8:50pm

    wovenlander

    3 posts

    will current_url() works?

    I got similar issue.
    I need to use javascript to direct request to a processing step and redirect back to original place.
    Could someone guide me how I can get this done?

    Javascript already knows the current URL, it’s at [removed].href

    Assign that to a hidden field in your form, or append it to your query string, so it’ll go to the server when the form is submitted; and then your controller can redirect back to it.

    Try writing a little Javascript that outputs the location.href into the current page once it’s loaded. That way you can see if you’re getting the value you need to send them back.

    One thing: you generally want to HTMLencode the current URL for transmission in a GET or POST, and then decode it when you want to use it in a redirect.

  • #20 / May 01, 2012 1:50pm

    Kathy J. Lowrey

    1 posts

    You can use these functions.

    public function str_left($s1, $s2){
     return substr($s1, 0, strpos($s1, $s2));
    }
    
    
    public function get_self_url(){
    
     $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
     $protocol = $this->str_left(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
     $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
     return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
    }
  • #21 / May 01, 2012 3:27pm

    InsiteFX

    6819 posts

    $url = current_url();

    Returns the full URL (including segments) of the page being currently viewed.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases