0

When i use base_url as

$config['base_url'] = 'http://localhost'; 

It redirects to localhost/login/validate and shows object not found. Any idea why? But it works perfectly in live server when i set base_url to domain.

$config['base_url'] = 'http://designhub.com.np/educare'; 
Dipesh Shrestha
  • 57
  • 1
  • 1
  • 9

3 Answers3

1

you can use this code in config.php

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


$root  = "http://".$_SERVER['HTTP_HOST'];

/*assets path*/
define('HTTP_CSS_PATH', $config['base_url'].'assets/css/');
define('HTTP_DOC_PATH', $config['base_url'].'assets/docs/');
define('HTTP_IMAGES_PATH', $config['base_url'].'assets/images/');
define('HTTP_JS_PATH', $config['base_url'].'assets/js/');
define('HTTP_IMG_PATH', $config['base_url'].'assets/img/');

you can use it local as well as on server too

Rahul Borole
  • 174
  • 2
  • 9
  • It's a cool trick, but Codeigniter's code itself actually discourages this behavior as it can be not secure. If it is not set, then CodeIgniter will try guess the protocol and path | your installation, but due to security concerns the hostname will be set | to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise. | The auto-detection mechanism exists only for convenience during | development and MUST NOT be used in production! (From application\config\config.php) – kchason Oct 10 '17 at 12:23
0

When your on a local host set it some thing like

$config['base_url'] = 'http://localhost/yourproject/';

When use live domain

$config['base_url'] = 'http://www.yourdomain.com/';
  • Thanks worlfgang1983, changes works but there is nothing in dashboard – Dipesh Shrestha Oct 10 '17 at 07:21
  • Can you be more clear please but there is nothing in dashboard?? –  Oct 10 '17 at 07:22
  • Did you follow codeigniter file and naming way explained here http://www.codeigniter.com/user_guide/general/styleguide.html#file-naming –  Oct 10 '17 at 07:24
  • @DipeshShrestha Also try with index.php in url `http://localhost/yourproject/index.php/dashboard` if that works then you need a suitable htaccess for your project –  Oct 10 '17 at 07:25
  • designhub.com.np/educare login: admin@gmail.com pwd: admin you can login and see dashboard there. – Dipesh Shrestha Oct 10 '17 at 07:34
0

You should write the folder name in which the project files are: (with localhost)

$config['base_url'] = 'http://localhost/project_folder_name/';

As your live server has your project files under root folder like public_html so you can use base_url as you mentioned.

But with local, write folder name after localhost as I have mentioned.

Himanshu Upadhyay
  • 6,558
  • 1
  • 20
  • 33