Subcookies V2
Posted on 09 May 2008 (02:47 PM)
My Subcookies article from May the 27th of last year has proven to be my most popular bit of writing.
A year after publishing, "C" has requested an update.
I have now rewritten my cookies script, fixing some issues pointed out by "C", and added some security as pointed out by Jim Thomson.
Notable changes:
Note; for a complete rundown of the original script, read Subcookies.
- The
subcookiejar.fetch ()method now returns an object literal (or, as the cool kids say, "JSON") if the second parameter is left undefined. This means that by doing the following...// bake a new cookiesubcookiejar.bake ('admin', {name: 'Harmen',age: 23,homepage: 'http://www.whatstyle.net'}, 2);// fetch itvar admin = subcookiejar.fetch ('admin');- Download this code: /code/subcookies_v21.txt
alert (admin.name);alert (admin.age);alert (admin.homepage);- Download this code: /code/subcookies_v22.txt
- If the second parameter is given, however,
subcookiejar.fetchwill return eithernullif the requested subcookie is not available, or just that subcookie. - Also, it is now possible to append to existing cookies. If, after executing the code above, I execute the following code...
subcookiejar.bake ('admin', {city: 'Harderwijk',country: 'The Netherlands'}, 2);- Download this code: /code/subcookies_v23.txt
{name: 'Harmen',age: 23,homepage: 'http://www.whatstyle.net',city: 'Harderwijk',country: 'The Netherlands'}- Download this code: /code/subcookies_v24.txt
Other changes consist purely of improving some code, comments and security checks.
So, the new version can be downloaded here. Go and grab it, it's free!
As always, I'd love to hear feedback. If you have any, do let me know.
And C, sorry to keep you waiting ;).
Filed under Javascript
- ← previous article: Help the UN World Food Program to end world hunger
Comments:
OMG!! I love you man!! I really do! : )
''
And C, sorry to keep you waiting ;)
"
It worth all the waiting! ; )
this comment has been quoted by Harmen Janssen
Good!
I'm glad you're satisfied with my update. :)