New version php language detection script.
stuartindigo
Status: New User - Welcome
Joined: 08 Aug 2007
Posts: 2
Reply Quote
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
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
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!
stuartindigo
Status: New User - Welcome
Joined: 08 Aug 2007
Posts: 2
Reply Quote
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
Display posts from previous:   

All times are GMT - 8 Hours