4

Hi there good people of StackOverflow, I have a problem and I was hoping that some of you out there might be able to help me. Let's say I am supposed to create some kind of Wordpress web shop on www.webshop.com domain, written in English language, with a cookie named 'cartItems' available for that domain. Ok, not a problem.

The problem is that I also need to make a german version of the site and I need to make difference between english and german cookies.

Now, my question is, if for example the german site is on the www.webshop.com/de/ I can set a german cookie to be available only for the /de/ domain, right? But how can I set that english cookie will be available in all the domains except the /de/ one.

If that can't be done would it be possible if the german site was on de.webshop.com

Thank you for all the help

Slavenko Miljic
  • 3,836
  • 2
  • 23
  • 36
  • 2
    `/de/` is not a domain. Why not store a language flag inside the cookie, or even inside the server-side backend? – Kerrek SB Sep 07 '11 at 21:46
  • Yeah i understand that I just didn't know how to express myself properly. I cant use the same cookie because of the different currencies and whatnot, I guess that it could be done with some kind of conversion but I'm not that good :) – Slavenko Miljic Sep 07 '11 at 21:53
  • 2
    It's called a "path", and given that that very same term is used in the specification of cookies, it's a little worrying that you should be unfamiliar with it while trying to build a money transacting application with this very technology. Anyway, cookie paths may not solve your problem, but I somehow wonder if this is good design at all; I have a feeling that all this should be done server-side, and your cookie should really only track the session ID... – Kerrek SB Sep 07 '11 at 21:56
  • I'm not doing much of the programming regarding the webshop, it's a wordpress theme that is already set up. I need to separate those two shops because the prices are different in euros and in dollars since the theme doesn't support different currencies. Oh and thank you for trying to help – Slavenko Miljic Sep 07 '11 at 22:05
  • 2
    Well, if the web application is fixed, can't you put one under `/en/` and one under `/de/` and run them in parallel, rather than having one nested under the other? – Kerrek SB Sep 07 '11 at 22:07
  • You see..that is a very good question? Why didn't I think of that this morning when they decided to go with this. Alrighty then, I guess that is probably the smartest thing to do. Thanks, thy will be done :) – Slavenko Miljic Sep 07 '11 at 22:11

3 Answers3

5

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.

Lepidosteus
  • 11,779
  • 4
  • 39
  • 51
3

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.

alexp
  • 3,587
  • 3
  • 29
  • 35
0

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

Hassan Al-Jeshi
  • 1,450
  • 2
  • 15
  • 20
  • The funny thing is I've used that plugin up until yesterday and it worked great (it's free for Wordpress v 3.0.5) but now i have to make changes because of the cart/currency/idontevenknowanymore issues. Thank you for the comment – Slavenko Miljic Sep 07 '11 at 21:55