These are chat archives for codeigniter-id/codeigniter-id.github.io

10th
Aug 2017
Samuele
@eleumas
Aug 10 2017 17:55

I'm bulding a multilanguage site with codeigniter.
I have put the controller and the view inside 2 different folder named IT and EN.
After, i have set the routes and created a controller named Language inside the folder controller with this code:

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Language extends CI_Controller {

public function index() {

$lc = "";
  // Check to see that the global language server variable isset()
  // If it is set, we cut the first two characters from that string
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
  $lc = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);

if($lc == "it"){
  header("location: it/home");
  exit();
} else if($lc == "en"){
  header("location: en/home");
  exit();
}
else{ y
  header("location: it/home");
  exit();
}
}
}
?>

I would like detect the browser language and redirect the user. My method is correct? There are other better methods? Thanks to all.