New version php language detection script.
I'm fighting to try to get this working - I'm a little confused about the implementation of the script (specifically the $feature detail).
I've presently got this :: Code :: function get_languages( $feature, $spare='' )
{ // get the languages $a_languages = languages(); $index = ''; $complete = ''; $found = false;// set to default value //prepare user language array $user_languages = array(); $feature=='header' followed by this for the redirection :: Code :: elseif ( $feature == 'header' )
{ switch ( $user_languages[0][1] )// get default primary language, the first one in array that is { case 'en': $location = 'en/index.php'; $found = true; break; case 'es': $location = 'es/index.php'; $found = true; break; case 'de': $location = 'de/index.php'; $found = true; break; case 'fr': $location = 'fr/index.php'; $found = true; break; default: break; } if ( $found ) { header("Location: $location"); } else// make sure you have a default page to send them to { header("Location: de/index.php"); } } } I'm obviously doing something wrong, but don't know what. Help please! Stuart Back to top |
|||||
get_languages( $feature, $spare='' )
is the function name. It takes 1 argument, second is optional when calling the function: get_language('header'); will trigger the 'header' behavior. Depending on what the function is supposed to do, return something or do something, you'd also put the value into a local variable for further processing if it returns something. The script is loaded as an include, then you call it using the function name in the main page, whereever you want that data to occur. Remember, for debugging, echo is your friend, to test outputs, as is print_r to print out arrays to make sure the data is correct. Back to top |
|||||
Working!
Thanks for the information. I finally managed to get it working properly.
I ended up using a very simple page to just call the function for the redirect. FYI here's the page as a sample implementation :: Code :: <?php
include 'langcheck.php'; get_languages('header'); ?> I've also used full url's in the header(location: ......) points (I believe this is the recommended method in php). Stuart Back to top |
|||||
All times are GMT - 8 Hours
|