noushid p
noushid p

Reputation: 1483

How to get Base URL with port number in codeigniter 3.0.3

I am currently using codeigniter 3.0.3 .I tried to get base url using var_dump(base_url());function
i got this result

string 'http://localhost/' (length=17)

But I need to get base URL with port number.I got it in codeigniter 3.0.2 like this

string 'http://localhost:8000'

How to get Base URL with port number in codeigniter 3.0.3.

Upvotes: 3

Views: 11253

Answers (3)

noushid p
noushid p

Reputation: 1483

Set base_url in config.php like this

$config['base_url'] = 'http://'. $_SERVER['HTTP_HOST'].'/';

Upvotes: 5

Tpojka
Tpojka

Reputation: 7111

You could trim the trailing slash from the base url, and add the port number of the current request, like this:

$trimmedBaseUrl = rtrim(base_url(), '/');
$serverPort = $_SERVER['SERVER_PORT'];
$newBaseUrl = "$trimmedBaseUrl:$serverPort/";

var_dump($newBaseUrl);

Upvotes: 1

Vahe Galstyan
Vahe Galstyan

Reputation: 1731

You can do something like this

var_dump(base_url().$_SERVER['SERVER_PORT']);

Upvotes: -1

Related Questions