Site Navigation
vegUISiteKit - The cookie functions library
written by vegu on 15 Mar, 2007 08:05:36
The VSK cookie functions library allows to set, unset and read cookies comfortably using javascript.
I used to do all the cookie setting via PHP / ajax whatever, kind of a mental black out i guess :) It's much more convenient to just do it using javascript once you have set up a couple functions for it.
To set a cookie using VSK we have the
vsk_cookie_set() function.
Example:vsk_cookie_set('mycookie', '123 test', 1000*60*60);
The example above would set a cookie variable by the name of
mycookie with it's value being
123 test. The third argument is the validity time of the variable in milliseconds - in this case 1 hour, this argument is optional and if omitted will cause the variable to be valid until it gets deleted. There is a fourth argument that is also optional that lets you specify the path component of the variable setting it only for a certain location of your website.
Unsetting the cookie
You can simply erase a cookie variable by calling the
vsk_cookie_unset() function. All this function takes is the name of the cookie variable you want to get rid of.
Example:vsk_cookie_unset('mycookie');
Retrieving cookie variables
To retrieve a single cookie variable VSK provides you with the
vsk_cookie_get() function.
Example:var v = vsk_cookie_get('mycookie');
alert(v);
You can also retrieve a list of all active cookie variables for the current location by calling the
vsk_cookie_list() function. It returns an object that has a property for every cookie variable. So instead of using vsk_cookie_get several times to retrieve the same variable - which involves parsing of strings to retrieve by the way - you simply get the list and read the variable from there.
Example:var l = vsk_cookie_list();
alert(l.mycookie);
Related Posts
Your Comment
Comments
No comments yet.