简体   繁体   English

使用javascript创建一个cookie(已经从Set-Cookie标头中获得了整个cookie字符串)

[英]Create a cookie with javascript (got a whole cookie string already from Set-Cookie header)

I know this was asked before, but I have a little bit of a different situation: 我知道这是以前问过的,但是我有一些不同的情况:

I need to create a cookie with javascript with this 'Set-Cookie' string (got it from curl headers within PHP): 我需要使用此'Set-Cookie'字符串(使用PHP中的curl标头获取它)使用javascript创建一个cookie:

.SOMEAUTH=LONGRANDOMSTRINGDLSAKSD325KFASFCAK32LONGRANDOMSTRING; expires=Sat, 01-Feb-2014 11:11:25 GMT; path=/; HttpOnly

A cookie is supposed to be created with 应该使用以下方式创建Cookie:

document.cookie = <cookie string data>; 

right? 对?

Everyone builds their cookies up with name, date and then that path=/ at the end as I see... I have the mentioned string as variable in javascript. 每个人都用名称,日期和最后的path = /来建立他们的cookie,如我所见...我在javascript中将提到的字符串作为变量。 If I do 如果我做

document.cookie = data; 

where data is my string above, the cookie is not created (I should see it in browser resources right?) 上面的数据是我的字符串所在的位置,则不会创建cookie(我应该在浏览器资源中看到它吗?)

What am I doing wrong? 我究竟做错了什么? Should HttpOnly be there? HttpOnly应该在那里吗?

Thanks for any help - if I was unclear please ask for more info 感谢您的帮助-如果不清楚,请询问更多信息

Remove HttpOnly and it will work. 删除HttpOnly,它将起作用。 Javascript cannot set HttpOnly due to its.. well nature. Javascript由于其良好的性质而无法设置HttpOnly。 it is in fact http only. 它实际上只是http。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM