codeigniter get base url code example
Example 1: get current url in codeigniter
simple get like this
echo $this->input->get('my_id');
Load the URL helper To get current url
$currentURL = current_url(); //http://myhost/main
$params = $_SERVER['QUERY_STRING']; //my_id=1,3
$fullURL = $currentURL . '?' . $params;
echo $fullURL; //http://myhost/main?my_id=1,3
Example 2: codeigniter base_url
$this->load->helper('url');
Example 3: dynamic base url codeigniter
defined('BASE_URL') OR define('BASE_URL', (is_https() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . '/');
$config['base_url'] = BASE_URL;
Example 4: codeigniter base url automatic
$base_url = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$base_url .= "://". @$_SERVER['HTTP_HOST'];
$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $base_url;