Sla*_*jic 4 javascript php cookies
你好StackOverflow的人,我有一个问题,我希望你们中的一些人可以帮助我.假设我应该在www.webshop.com域创建一些Wordpress网络商店,用英语写成,并为该域名提供名为"cartItems"的cookie.好的,不是问题.
问题是我还需要制作该网站的德语版本,我需要区分英语和德语的cookie.
现在,我的问题是,如果德国网站在www.webshop.com/de/上,我可以设置德国cookie只适用于/ de/domain,对吗?但是如何设置除了/ de/one之外的所有域中都可以使用英语cookie.
如果德国网站在de.webshop.com上,那么就无法做到这一点
谢谢你的帮助
虽然当然你必须使用两个不同的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/');
Run Code Online (Sandbox Code Playgroud)
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');
Run Code Online (Sandbox Code Playgroud)
请注意:在域名".webshop.com"上设置cookie意味着该cookie将被发送到webshop.com的每个子域,无论它是什么.确保这是你想要的.
| 归档时间: |
|
| 查看次数: |
1479 次 |
| 最近记录: |