Welcome Guest, Not a member yet? Register   Sign In
Two base_url possible?
#1

[eluser]bjora857[/eluser]
When I code I use a local webserver. And when Im happy with my code I upload it to my web host. Nothing strange with that...

But every time I upload I have to change the commenting in my config file.

$config['base_url'] = "http://localhost:8888/";
//$config['base_url'] = "http://www.mydomain.com/";

Is there a better way?

something like this

psuedo code

if (isValid(http://localhost:8888/))
{$config['base_url'] = "http://localhost:8888/";}
else
{$config['base_url'] = "http://www.mydomain.com/;}
#2

[eluser]smith[/eluser]
used to do this:

Code:
if ($_SERVER['SERVER_NAME']=='something')
{
    some setup
}
else
{
    some setup
}
#3

[eluser]bjora857[/eluser]
it worked excellent. $_SERVER['SERVER_NAME']=='something' was just what I was looking for.
thanks
#4

[eluser]blackarma[/eluser]
Another solution : Put the hostname in a environment variable and load it directly.
#5

[eluser]Michael Wales[/eluser]
Code:
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= preg_replace('@/+$@','',dirname($_SERVER['SCRIPT_NAME'])).'/';

or

Code:
$proto = "http" .
    ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "") . "://";
$server = isset($_SERVER['HTTP_HOST']) ?
    $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
$config['base_url']    = $proto . $server;


From: this thread
#6

[eluser]mgnsrsn[/eluser]
Hi,

do I really need to have the site ip/name in the base_url? Cant I just specify the path. I.e. if I have http://server/code/ , cant I just set $config['base_url'] = "/code/" ? This would allow for unlimited sites (as long as the path is the same...)

Thanks
#7

[eluser]xwero[/eluser]
[quote author="mgnsrsn" date="1193336363"]Hi,

do I really need to have the site ip/name in the base_url? Cant I just specify the path. I.e. if I have http://server/code/ , cant I just set $config['base_url'] = "/code/" ? This would allow for unlimited sites (as long as the path is the same...)

Thanks[/quote]

You could try to put it in the index_page

$config['index_page'] = "code/index.php";

But i'm not sure it will work
#8

[eluser]mgnsrsn[/eluser]
My problem is that Im using base_url in all img, js, css links etc. And its also used in the form_open function by CI.

E.g.

<img src="&lt;?=base_url()?&gt;images/projectIcons/logo.gif" alt="">
&lt;?=form_open('app/login', array('name' => 'loginform', 'id' => 'loginform'))?&gt;

If I have multiple sites, or multiple networks to my site, I cant have a specific ip address/name configured in the base_url. Therefor I thought that I could leave the ip address/name out. It seems to work, but I wonder if I cause problems somewhere else in CI.

Any thoughts?
#9

[eluser]John_Betong[/eluser]
&nbsp;
There are numerous solutions to the different paths problem between http://localhost and the online version.

The way I do it is to have this define in my index.php and change the paths wherever required.


Code:
// index.php
define('LOCALHOST', file_exists('c:') );

// config.php
if (LOCALHOST) {
   $config['base_url']    = "http://localhost/" ;
}else{
   $config['base_url']    = "http://sitename.com/" ;
}
&nbsp;
&nbsp;
&nbsp;




Theme © iAndrew 2016 - Forum software by © MyBB