简体   繁体   中英

get cookie after set cookie

I've set my cookie using set-cookie as follows on the server's cgi scripts

print "Content-type: text/html\n";
sys.stdout.write(cookie.output())
print "\n\n";

but when I reload the page I can't get the cookie as it doesn't appear on

document.cookie

How do I get the cookies? and was Set-cookie : name=value supposed to appear on document.cookie after I refresh the page?

Overall I want the client side to recognize the cookie if exists and act accordingly

Thanks

W3Schools is explaining it beautifully. You can have a look at the function getCookie and setCookie provided in the website. You can use that as a base. Its pure javascript

Cookies are set out by the server. The client (browser) just sends them back. You cannot use Javascript to set cookies.

EDIT

You need fewer quotes and the \\r is not required. Probably need ; instead of , . ie

print "Content-type: text/html\n";
print "Set-Cookie: name=value\n\n";

Also use HTTP live header add-on for Firefox to check the HTTP communication.

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