這是可能的,當然你必須使用兩個不同的cookie名稱,一個用於EN數據,一個用於DE數據。
使用不同的路徑(用於www.webshop.com EN和www.webshop.com/de/爲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/');
爲cookie路徑是向後阻擋(它只能從所讀目錄或其子目錄中,而不是父目錄),因此如果您使用/ de/path設置cookie,則可以從/ de /或/ de/foo /中讀取它,但不能從/或/ bar中讀取/。同樣,如果你設置一個路徑爲/的cookie,它可以在/ de /或/ de/foo /或/ bar /上讀取。
使用不同的域(www.webshop.com爲EN和de.webshop.com爲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');
注意:設置在域」 .webshop的cookie。COM」表示該cookie將被髮送到每子域webshop.com的,不管它是什麼。確保這就是你想要的。
'/德/'是不是域,爲什麼不保存語言標誌內的cookie,甚至內部的服務器端後端? –
是的,我明白,我只是不知道如何正確表達自己。我不能使用相同的cookie,因爲不同的貨幣和whatnot,我想它可以做一些轉換,但我不是那麼好:) –
它被稱爲「路徑」,並且鑑於在cookies的規範中使用了非常相同的術語,有點擔心你應該不熟悉它同時試圖用這種技術構建一個錢交易應用程序。無論如何,Cookie路徑可能無法解決您的問題,但我以某種方式不知道這是否是好設計;我有一種感覺,所有這些都應該在服務器端完成,並且您的Cookie應該只能跟蹤會話ID ... –