Posted By

lifewishes on 10/20/10


Tagged

cookies codeigniter


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

MaxLazar


codeigniter detect language using cookie and load it


 / Published in: PHP
 

  1. /**
  2. * load language
  3. *
  4. */
  5. /* function load_language()
  6. {
  7. if( get_cookie('lang_en')=="en" ) {
  8. $this->lang->load('fusers', 'english');
  9. }else{
  10. $this->lang->load('fusers', 'chines');
  11. }
  12. $cookie_en = array(
  13. 'name' => 'lang_en',
  14. 'value' => 'en',
  15. 'expire' => time()+86500,
  16. 'domain' => '',
  17. 'path' => '/',
  18. 'prefix' => '',
  19. );
  20. $cookie_ch = array(
  21. 'name' => 'lang_ch',
  22. 'value' => 'ch',
  23. 'expire' => time()+86500,
  24. 'domain' => '',
  25. 'path' => '/',
  26. 'prefix' => '',
  27. );
  28. // var_dump(get_cookie('lang'));
  29. if (isset($_POST['lang']) && $_POST['lang']=='en') {
  30. // delete chines
  31. if (get_cookie('lang_ch')) { delete_cookie("lang_ch"); }
  32. if (get_cookie('lang_en')) { delete_cookie("lang_en"); }
  33.  
  34. // en not already set
  35. if (!get_cookie('lang_en')) {
  36. set_cookie($cookie_en);
  37. }
  38. } else if (isset($_POST['lang']) && $_POST['lang']=='ch') {
  39. // delete english
  40. if (get_cookie('lang_en')) { delete_cookie("lang_en"); }
  41. if (get_cookie('lang_ch')) { delete_cookie("lang_ch"); }
  42.  
  43. // ch not already set
  44. if (!get_cookie('lang_ch')) {
  45. // set chines
  46. set_cookie($cookie_ch);
  47. }
  48. } else {
  49. // no language set then set english
  50. if (!get_cookie('lang_en') && !get_cookie('lang_ch') ) { set_cookie($cookie_en);}
  51. }
  52. }*/

Report this snippet  

You need to login to post a comment.