Jump to content

$_server["http_accept_language"]


driz
 Share

Recommended Posts

Hi, I'm playing around with an experiment. Basically if a user goes to domain.com and they are from the US it will auto redirect to domain.com/en-US/ and if they went to say domain.com/section/ it would auto direct to domain.com/en-US/section/Adding to this, I'd want the html tag to change based on the language so for example: xml:lang="en-US" lang="en-US"I've looked around and found $_SERVER["HTTP_ACCEPT_LANGUAGE"] to be the best way of doing this, is this the best way?and how could I use this to develop my experiment?Thanks

Edited by driz
Link to comment
Share on other sites

Well, the get_languages function in that code attempts to parse the list of languages in the http header, so the first step is to run that function and use print_r on the array that it returns to figure out what information you get from it. Based on whatever it returns (the array may contain more than one language), you can use that to do your redirect on the pages where you want to use the redirect.

Link to comment
Share on other sites

Thank you for all your input so far everyone. However I'm still not getting this to work.Can you provide a block of code as an example to demonstrate what your explaining, as I just can't get my head around it. Thank you again.

Link to comment
Share on other sites

The language should come from the code that you linked to. You should use that code to get the language. You should print the return value of that function to see what information it returns, it's probably going to return an array of languages. You call the function like this:$lang = get_languages('data');Then you can print the array out to see what it looks like:print_r($lang);Then once you know what data you have available, then you can figure out how you want to add that to the URL.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...