从http移至https时,无法维护jQuery Cookie [英] JQuery Cookie values not maintained while moving from http to https

查看:207
本文介绍了从http移至https时,无法维护jQuery Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jquery创建cookie,请参见以下代码:

I am creating cookie using jquery, please see below code:

var divID = $(link).next(".open-block-holder").find("div:first").attr("id");
$('#panelOpen').val(divID);                             
$.cookie('currentPanelOpen', divID);

以上Cookies'currentPanelOpen'是在HTTP页面中创建的,出于安全原因,现在在我的登录名上单击我正在HTTPS中重新加载整个页面".问题是我的cookie"currentPanelOpen"值在移至HTTPS页面时未得到维护. (仅第一次发生,一次进入https模式,然后再次返回到http页面并执行上述步骤即可正常工作)

the above Cookies 'currentPanelOpen' is been created in HTTP page, now on my login click I am reloading whole page in HTTPS for security reasons. The problem is that my cookie 'currentPanelOpen' value is not maintained while it is moving to HTTPS page. (happening only for first time, once gone to https mode and again coming back to http page and doing above step works fine)

令人惊讶的是,如果我直接以HTTPS模式打开页面,则该值将保持不变,并打开我单击的面板.

Surprisingly, If I directly open the page in HTTPS mode then the value is maintained and my clicked panel is opened.

请提出建议!

谢谢.

推荐答案

这是因为在常规HTTP会话中创建的cookie和在HTTPS会话中创建的cookie之间存在根本差异.后者也像连接一样被加密(因为如果您的连接被加密但是存储在计算机上的任何数据都没有加密,这将是一个巨大的安全漏洞)

That is because there is a fundamental difference between a cookie created in a normal HTTP session and a cookie created in an HTTPS session. The latter is encrypted much like the connection as well (because it would be a giant security hole if your connection is encrypted but any data stored on your machine weren't)

我有2条建议,其中一项可能无效:

I have 2 suggestions, one which might not work:

1)像这样使用cookie调用(前提是您使用的是我熟悉的cookie调用)

1) Use the cookie call like this (provided you're using the one I'm familiar with)

$.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });

并尝试将域设置为https(创建2个cookie,一个用于http,一个用于https),或者尝试使用安全"标志,true/false等.或者

And try to set the domain to https (creating 2 cookies, one for http, one for https) or by trying the "secure" flag, true/false etc. Or

2)使用jQuery的AJAX功能在PHP中创建用户会话(http://www.reynoldsftw.com/2009/03/using-jquery-and-ajax-to-create-php-sessions/),然后应该通过在重新加载到document.ready调用或代码本身中后将其打开来保持"panelOpen" div的方式,还应确保再次设置https cookie.

2) Use jQuery's AJAX ability to create a user session in PHP (http://www.reynoldsftw.com/2009/03/using-jquery-and-ajax-to-create-php-sessions/) which then should maintain the "panelOpen" div by way of either opening it up once it reloads in the document.ready call or in the code itself... also making sure to set the https cookie again.

这篇关于从http移至https时,无法维护jQuery Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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