CodeIgniter Forums
base_url and port number - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9)
+--- Thread: base_url and port number (/showthread.php?tid=65420)



base_url and port number - usr_ny - 06-09-2016

how can i construct the following URL for my site?

http://127.0.0.1:8080/appname/

calls to base_url() return this http://127.0.0.1/appname/


RE: base_url and port number - pdthinh - 06-10-2016

(06-09-2016, 01:14 PM)usr_ny Wrote: how can i construct the following URL for my site?

http://127.0.0.1:8080/appname/

calls to base_url() return this http://127.0.0.1/appname/

Set in application/config/config.php:

PHP Code:
$config['base_url'] = 'http://127.0.0.1:8080/appname/'



RE: base_url and port number - usr_ny - 06-10-2016

But the problem is, that I'm deploying to a server and I don't know what the server address or base URL will be.

The address can automatically change from  http://127.0.0.1:8080/appname/ to http://127.0.0.2:8081/appname/

So, I can't hard code the:

PHP Code:
$config['base_url'] = 'http://127.0.0.1:8080/appname/'


Can CI determine the base URL without me setting that config value?


RE: base_url and port number - pdthinh - 06-11-2016

This code is from CI manual, with some changes
PHP Code:
// change your domain below
$allowed_domains = array('domain1.tld''domain2.tld');
$default_domain  'domain1.tld';

if (
in_array($_SERVER['HTTP_HOST'], $allowed_domainsTRUE))
{
 
       $domain $_SERVER['HTTP_HOST'];
}
else
{
 
       $domain $default_domain;
}

// get server port
$port $_SERVER['SERVER_PORT'];

if ( ! empty(
$_SERVER['HTTPS']))
{
 
       $config['base_url'] = 'https://'.$domain.':'.$port.'/appname/';
}
else
{
 
       $config['base_url'] = 'http://'.$domain.':'.$port.'/appname/';