php - How to localize a language and redirect the user to a specific url with CodeIgniter -


i have created website in 2 languages codeigniter: english (en) , german (de).

the default page is: www.mysite.com

the url en is: www.mysite.com/en/ url de www.mysite.com/de/

now redirect user according his/her device language. know, script below it's not right way.

$lang = substr($_server['http_accept_language'], 0, 2); switch($lang){ case 'en': return redirect(site_url('en/')); break; case 'de'; return redirect(site_url('de/')); break; default: return redirect(site_url('en/')); } 

how can manage it?

i found there syntax error in code @ case 'de';

it case 'de':

$lang = substr($_server['http_accept_language'], 0, 2); switch($lang){ case 'en': redirect(site_url('en/')); break; case 'de': redirect(site_url('de/')); break; default: redirect(site_url('en/')); } 

and make sure have load url helper

$this->load->helper('url'); 

also remove return redirect


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -