简体   繁体   中英

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):

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

A cookie is supposed to be created with

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. 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?)

What am I doing wrong? Should HttpOnly be there?

Thanks for any help - if I was unclear please ask for more info

Remove HttpOnly and it will work. Javascript cannot set HttpOnly due to its.. well nature. it is in fact http only.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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