Base url in Codeigniter
Setting your base url in Codeigniter
You will need to set your base URL in
If it is not set, then CodeIgniter will try to guess the protocol and path to
your installation, but due to the security concerns the hostname will be set
$_SERVER['SERVER_ADDR'] if available, or localhost otherwise.
The auto-detection mechanism exists only for convenience during
development and MUST NOT be used in production!
It should be filed like
Always good to use
/ at end of
When you do not set your base URL you might run into some errors where you can not load your CSS, images, and other assets items. And also you might have trouble submitting forms as some users have come across.
If you do not want to set your base URL another way is.
Create a new core file in
And paste this code
Smart way to setting up the base_url
The following lines of code is more smart way to setting up the
base_url in codeigniter:
Because everyone knows the hosting space. So if you set like this you can prevent Injection to your site/host.
Something More About base_url
What happens if I don't set
You will not get any Impotency error to set this and proceed. You can continue without setting, but you should know about HTTP header injection
If I did't set it what will show up?
You will get
http://[::1]/ instead of your actual URL.
What does this mean
This is temporary URL which set by CI by Default. This will point the root of your document.
::1 - Server address (localhost) Read More about this
How to set proper
Base URL should always point to root of your project folder. (outside application folder)
How to use
Most common use is to find the right path to your js or css files.
Adding the code above in your view will produce HTML as below: