Skip to content

Instantly share code, notes, and snippets.

@ptasker
Created December 4, 2012 21:19
Show Gist options
  • Select an option

  • Save ptasker/4208792 to your computer and use it in GitHub Desktop.

Select an option

Save ptasker/4208792 to your computer and use it in GitHub Desktop.
Detect French browser lang
<?php
/**
@uses CodeIgniter 2.1
Grab the user's language from the HTTP_ACCEPT_LANGUAGE string.
*/
if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) {
$pieces = explode( ",", $_SERVER['HTTP_ACCEPT_LANGUAGE'] );
if ( isset( $pieces[0] ) && stristr($pieces[0], 'fr') ) {
if ( !$this->input->get( 'lang' ) ) {
redirect( "FRENCH URL" );
return;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment