I want to know how can I detect the client language so if it's arabic then leave it as www.mydomain.com but if it's english then redirect to www.mydomain.com/en?
detect client language
That information is supplied in the Accept-Language request header (available in PHP as $_SERVER['HTTP_ACCEPT_LANGUAGE']
does PHP has global file similar to the global or config files in ASP.NET or I should add the language check in every php file in my website?
session_start() combined with the super global array (always available everywhere, after session_start()) $_SESSION.
That information is supplied in the Accept-Language request header (available in PHP as $_SERVER['HTTP_ACCEPT_LANGUAGE']
You should also note that the Accept-Language header can (and usually does) contain multiple languages. So you'll have to use a regexp to see if the target language is contained in the string
Thanks. I have one more question..
My default website and files in root are in arabic so the detection will be placed in that index.php then if the cluent language is english it will redirect to the /en
Now, after being redirected, if user wants to go to the arabic website he will click the ARABIC link whjch should go to the index.php but guess what will happen...! It will keep redirecting to the /en..
How can i prevent this?
Provide the link back to the Arabic version with something that distinguishes it from the first visit, e.g. add something to the query string that you can check for.
That way, inside your index.php file, you can check for the presence of that parameter and avoid doing the automatic detection and redirection.
Thanks.. sorry but could you please guide on how to do it..
my main website (root) is in arabic.
I have a /en folder for the English website
but I can have www.mydomain.com/ar pointing to the arabic root using htaccess
so how can I do it in code to say if it's www.mydomain.com then check the language but if it's /en or /ar then no need to check?
jrahma;10993433 wrote:Thanks.. sorry but could you please guide on how to do it..
my main website (root) is in arabic.
I have a /en folder for the English website
but I can have www.mydomain.com/ar pointing to the arabic root using htaccess
so how can I do it in code to say if it's www.mydomain.com then check the language but if it's /en or /ar then no need to check?
What if they arrive on a page that is not the home page? To allow for that case you should automatically detect the language on every page, then redirect to the correct language. If you use sessions you can set a session variable "language_check" or something like that. If language_check = 0 you check the desired language and redirect if needed. If language_check = 1, then you have already redirected and you do nothing.
You just put a php include in the header of every page to check for the language. If you have html pages you need to modify your .htaccess file to parse .html pages for php.