PHP和Javascript cookie [英] PHP and Javascript cookies

查看:61
本文介绍了PHP和Javascript cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用PHP访问使用jQuery的cookie插件编写的cookie吗?我知道你不能将Javascript设置为等于PHP,反之亦然,但IN ESSENCE是:

Can I access a cookie written with jQuery's cookie plug-in with PHP? I know you can't set Javascript equal to PHP or vice versa, but IN ESSENCE is:

$.cookie('var') = $_COOKIE['var']?

同样,我知道你不能将它们设置为彼此相等,但如果我把它设置为jQuery然后转到另一个页面,可以通过PHP访问它吗?我已经阅读了很多关于此的帖子,但我似乎找不到这个部分的答案。

Again, I know you can't set them equal to each other, but if I set it in jQuery and then go to another page, can PHP access it? I've read lots of posts about this, but I can't seem to find an answer to this part.

注意,如果我查看Firefox的偏好,我可以看到饼干在那里,所以我知道它们已被设置。

Note, if I look in Firefox's preferences, I can see the cookies are there, so I know they're set.

推荐答案

是。

但是...... Klaus Hartl的jQuery cookie插件(我假设这是你正在使用的那个)默认设置cookie的路径到当前文件的那个。如果您尝试回复的PHP文件位于不同的文件夹中,则不会发送cookie。

But... Klaus Hartl's jQuery cookie plugin (I'm assuming this is the one you are using) defaults to setting the cookie's path to that of the current document. If the PHP file you were trying to echo from was in a different folder, the cookie wouldn't have been sent.

您可以在设置时设置cookie的路径cookie:

You can set the cookie's path when you set the cookie:

$.cookie('name', val, { path: '/' });

这篇关于PHP和Javascript cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆