driz Posted May 5, 2009 Share Posted May 5, 2009 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 More sharing options...
driz Posted May 5, 2009 Author Share Posted May 5, 2009 I've come across a script: http://techpatterns.com/downloads/scripts/...e_detection.txt not sure if that is any help for anyone? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 5, 2009 Share Posted May 5, 2009 Does that answer your question? Link to comment Share on other sites More sharing options...
driz Posted May 5, 2009 Author Share Posted May 5, 2009 No! Basically I'm still confused how to apply this to a website so that it would flow smoothly. I posted that code as it seemed like it would a good starting point? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 5, 2009 Share Posted May 5, 2009 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 More sharing options...
driz Posted May 6, 2009 Author Share Posted May 6, 2009 I'm half with you, basically I get that the function will find out the language for me, so for example 'en-us'. What I don't get is how I to use this to redirect the URL's. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 6, 2009 Share Posted May 6, 2009 You send a location header to redirect to a URL. e.g.:header('Location: http://www.google.com'); Link to comment Share on other sites More sharing options...
driz Posted May 6, 2009 Author Share Posted May 6, 2009 How do I link that up with the language code above? Link to comment Share on other sites More sharing options...
justsomeguy Posted May 6, 2009 Share Posted May 6, 2009 You just add the variable that holds the language the same way you do with any other string. e.g.:$url = 'domain.com/' . $language . '/section/'; Link to comment Share on other sites More sharing options...
driz Posted May 13, 2009 Author Share Posted May 13, 2009 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 More sharing options...
justsomeguy Posted May 13, 2009 Share Posted May 13, 2009 I'm not sure which part you don't understand, but to substitute a variable into a string you use the string concatenation operator, which is the period.$domain = 'google';header('Location: http://' . $domain . '.com'); Link to comment Share on other sites More sharing options...
driz Posted May 13, 2009 Author Share Posted May 13, 2009 Hi, I don't get how to get this to work, so get the information such as en-gb, and then attach it to the header redirect. Link to comment Share on other sites More sharing options...
justsomeguy Posted May 13, 2009 Share Posted May 13, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.