CodeIgniter – Tips

(Why should we use $_SERVER[‘SERVER_NAME’] and not LOCALHOST in base_url ?)

$_SERVER[‘SERVER_NAME’] – this will produce the exact server name. For example: your computer’s IP is and echo $_SERVER[‘SERVER_NAME’] the output is:

input : echo $_SERVER[‘SERVER_NAME’];


Issue: (note: assuming that you are a SERVER) If you are using base_url() and set it to (localhost/www/site/) to extend that path of your css, scripts links etc. This would be helpful. For example: <?php echo base_url(‘assets/css/bootstrap.css’); ?> this will produce http://localhost/www/site/assets/css/bootstrap.css. If the CLIENT request for the site no css file will be loaded because its also producing the url of css to LOCALHOST. That’s the reason we should use $_SERVER[‘SERVER_NAME’], it will produce the right servername.


One thought on “CodeIgniter – Tips

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s