Setting Cookies On Domain/subdomain
Solution 1:
It is possible, although of course you have to use two different cookie name, one for the EN data and one for the DE data.
Using a different path (www.webshop.com for EN and www.webshop.com/de/ for DE):
// this will be available everywhere, both on the english version and the german one
setcookie ('my_en_cookie_name', 'some data', time() + 24*30*3600, '/');
// this will only be visible when accessing the german website, english version user won't be able to see it
setcookie ('my_de_cookie_name', 'some other data', time() + 24*30*3600, '/de/');
Path for cookie is backward blocking (it can only be read from the directory specified or from a subdirectory of it, not from a parent one), so if you set a cookie with the /de/ path, it can be read from /de/ or /de/foo/ but not from / or /bar/. In the same way if you set a cookie with a path of /, it can be read on /de/ or /de/foo/ or /bar/.
Using a different domain (www.webshop.com for EN and de.webshop.com for DE):
// this will be available everywhere, both on the english version and the german one
setcookie ('my_en_cookie_name', 'some data', time() + 24*30*3600, '/', '.webshop.com');
// this will only be visible when accessing the german website, english version user won't be able to see it
setcookie ('my_de_cookie_name', 'some data', time() + 24*30*3600, '/', 'de.webshop.com');
PAY ATTENTION: Setting a cookie on the domain ".webshop.com" means that this cookie will be sent to every subdomain of webshop.com, no matter what it is. Make sure that's what you want.
Solution 2:
There are 3 ways you can separate the English and German cookies
1) Domain: You could use a separate www. and de. subdomain as you mentioned. To me this would be the easiest
2) Path: You can use the path, but if your English cookie is set for "/" it will still be accessible under "/de/". So if you want to go this route you'd need to make a "/en/" path as Kerrek suggested.
3) Name: Give the German cookie a different name
You will need to do one of those 3 to have separate English and German cookies. I'd think that having a separate subdomain would be the best, because not just your cookie paths but all your asset paths will be the same regardless of language.
Solution 3:
Personally I have used this plugin to solve this problem: http://wpml.org/
But if you prefer a free solution, here is a very good article: http://codex.wordpress.org/Multilingual_WordPress
Post a Comment for "Setting Cookies On Domain/subdomain"