Welcome Guest, Not a member yet? Register   Sign In
base_url and port number
#1

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/
Reply
#2

(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/'
Reply
#3

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?
Reply
#4

(This post was last modified: 06-11-2016, 05:52 AM by pdthinh.)

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/';

Reply




Theme © iAndrew 2016 - Forum software by © MyBB