Jump to content

$_server["http_accept_language"]


driz

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...