Jump to content

Getting language from user.


denbuzze

Recommended Posts

This is my current code:

 

<?php
$base = "http://www.test.com/";
$lang = strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2));
if($lang == "nl"  || $lang=="de" || $lang=="en" || $lang=="fr") {
	header('Location:' . $base . $lang . '/index.htm');
}
else {
	header('Location:'. $base . 'en' . '/index.htm');
}
?>

 

It works fine, but I want to keep in mind of the usability for the users.

 

So I have 2 questions:

1) If a user clicks on the site on e.g. "francais" (on index.htm) how do I keep a cookie to remember that the following visit, the user has to be automaticaly directed to the french section (the cookie should be 'fr').

 

on the site I have a link <a href="../fr/index.htm"> then the cookie should be fr

 

2) How do I add this (question 1) to the above code (I think with an additional if structure).

 

 

It was hard to formulate this questions well, but here my complete thoughts (SEMI-CODE)

 

If (cookie exists){

$lang_cookie = get the value of the cookie; (nl/de/en/fr)

$header('Location:' . $base . $lang_cookie . '/index.htm');

}

else {

--- here I put the above code ---

}

 

 

Please don't give me any comment like 'read the entiry php manual' or 'here you have some explanation about cookies'

 

Link to comment
https://forums.phpfreaks.com/topic/44628-getting-language-from-user/
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.