These are chat archives for codeigniter-id/

Aug 2017
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:

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
  $lc = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);

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

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