Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between site_url() and base_url()?

As I have read in some resources, base_url() and site_url() functions in codeigniter are almost the same, although my version of codeigniter (2.1.3) does not have a site_url() in it's config.php file (in config directory).

Yet are there differences between them in any way since I have seen site_url() with parameters and never seen base_url() holding none?

like image 609
Reza Saberi Avatar asked Jun 13 '13 05:06

Reza Saberi


People also ask

What is base_url () in php?

Understanding base_url()php file along with a trailing slash appended to the end of the URL. If the domain name is example.com and the website is using HTTPS as well as www. Further, the index. php file exists in the public_html directory then the base_url() would be https://www.example.com/.

What is base_url?

The URL found in the address bar of the front page of a website is its base URL. In other words, the common prefix found while navigating inside a given website is known as the base URL. One can select a base URL from the list of those available with help of the URL general properties page.

Where is Site_url in CodeIgniter?

site_url() Returns your site URL, as specified in your config file. The index. php file (or whatever you have set as your site index_page in your config file) will be added to the URL, as will any URI segments you pass to the function, and the url_suffix as set in your config file.

How base URL is defined in CodeIgniter?

Base URL should be absolute, including the protocol: $config['base_url'] = "http://somesite.com/somedir/"; If using the URL helper, then base_url() will output the above string.


1 Answers

echo base_url(); // http://example.com/website echo site_url(); // http://example.com/website/index.php 

if you want a URL access to a resource (such as css, js, image), use base_url(), otherwise, site_url() is better.

for a detailed reference Check this both function in CodeIgniter.

public function site_url($uri = '')     {         if (empty($uri))         {             return $this->slash_item('base_url').$this->item('index_page');         }         $uri = $this->_uri_string($uri);         if ($this->item('enable_query_strings') === FALSE)         {             $suffix = isset($this->config['url_suffix']) ? $this->config['url_suffix'] : '';             if ($suffix !== '')             {                 if (($offset = strpos($uri, '?')) !== FALSE)                 {                     $uri = substr($uri, 0, $offset).$suffix.substr($uri, $offset);                 }                 else                 {                     $uri .= $suffix;                 }             }             return $this->slash_item('base_url').$this->slash_item('index_page').$uri;         }         elseif (strpos($uri, '?') === FALSE)         {             $uri = '?'.$uri;         }         return $this->slash_item('base_url').$this->item('index_page').$uri;     } 

Base URL function.

public function base_url($uri = '')         {             return $this->slash_item('base_url').ltrim($this->_uri_string($uri), '/');         } 
like image 139
Fasil kk Avatar answered Oct 12 '22 02:10

Fasil kk