Skip to content

Instantly share code, notes, and snippets.

@tobystokes
Created May 22, 2014 10:40
Show Gist options
  • Save tobystokes/a1bd24549c8fcbfbe8a3 to your computer and use it in GitHub Desktop.
Save tobystokes/a1bd24549c8fcbfbe8a3 to your computer and use it in GitHub Desktop.
set language folder based on cookie or browser.
<?php
//previous visits will hopefully have lang cookie set. if no cookie, try browser lang
$lang = (isset($_COOKIE["lang"])) ? $_COOKIE["lang"] : substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
switch ($lang) {
case 'en':
header('Location: /en/');
break;
case 'de':
header('Location: /de/');
break;
case 'fr':
header('Location: /fr/');
break;
default:
header('Location: /en/'); // nothing going. give up use english.
break;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment