CodeIgniter – Tips

ronscript blog

(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 192.168.0.2 and echo $_SERVER[‘SERVER_NAME’] the output is:

input : echo $_SERVER[‘SERVER_NAME’];

output: 192.168.0.2

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.

View original post

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s