//
you're reading...
Programming

CodeIgniter Automatic Config BaseURL

CodeIgniter Logo

Sebel gak sih kalo kita harus berkali2 mengubah $config[’base_url’] gara2 pindah lokasi/environment? Well, I do.

Untungnya, di wiki CI ada yang baik hati membagi jurus saktinya😀

Buka file config.php, dan masukkan kode ini

$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']); 

Save, and.. tada! Base URL nya akan otomatis sesuai dengan environment yg kita gunakan.

Alternatif lain, gunakan kode ini untuk HTTP dan HTTPS:

$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

atau ini

$config['base_url'] = 'http' . ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 's' : '') .'://'.$_SERVER['HTTP_HOST'].str_replace('//','/',dirname($_SERVER['SCRIPT_NAME']).'/');

That’s it. Have a nice day!

Diskusi

2 thoughts on “CodeIgniter Automatic Config BaseURL

  1. maaf mas, kalo mau belajar tentang codeIgniter gimana/dimana ya referensinya?
    dasar2 yang harus dikuasai apa saja??
    maaf, saya masih awam dalam programming php.
    terimakasih🙂

    Posted by edofaqeeh | 06/05/2011, 18:54

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: