Welcome Guest [Log In] [Register]
Search Members Calendar | Rules ZB Code Index IF Code Index
ZBCode
  • Navigation
  • ZBCode
  • Coding Resources
  • Zetaboards Modifications
  • [Coders Only] ZetaBoards Cookies
Hey, welcome to ZBCode, the premier coding forum for ZB. Here you fill find some of the best Invisionfree and Zetaboards Codes on the network! Unfortunately, you're sorta hovering around in guest mode at the moment; why not join in on the fun? Register an account and you can start accessing the wealth of resources we have available here. Enjoy your stay at ZBCode, and remember to tell all your friends about us; the more members, the more codes available. ;)

Interested in joining? Click here.


If you are already a member of ZBCode, feel free to login right here:

Username:   Password:
Locked Topic
[Coders Only] ZetaBoards Cookies
Tweet Topic Started: Apr 19 2010, 04:52 PM (1,076 Views)
Reid Apr 19 2010, 04:52 PM Post #1
Member Avatar
What? The land of the free? Whoever told you that was your enemy.

Posts:
1,790
Group:
Distinguished Coder
Member
#148
Joined:
Jul 20, 2008
Setting cookies on ZB is a pesky chore, something that we often run out and find a fast cookie function for. However, there are situations on ZB where the cookie functions are either inadequate or require extra work.

For example, setting a regular cookie will often default the path to something pesky like /topic/12345 or other various nuisances. Not only this, but calculating the correct path is something I find myself wishing I could do quite often, and then I have to modify the cookie functions in order to take into account my calculations, etc... it's just one big mess.

With that in mind, I finally hit the breaking point and decided to write my own library of cookie functions. They are not complex, nor are they really anything different than the various cookie functions across the web. They are not extremely flexible, but they are one thing: customized for use on ZetaBoards.

You may use the following snippet of code (above yours, of course) in order to activate the functions:
Code:
 
<script type='text/javascript' src='http://z3.ifrm.com/313/104/0/p312803/zeta_cookie.js'></script>
This code will not overwrite any existing codes, so have no worries about any sort of conflicts. The reason I opted for this is because, hopefully, this code could be included inside of many other codes, so the script could be loaded multiple times on the same board. That should not be a problem.

All of the functions are contained in one, nice object, only polluting one value: zeta_cookie. I opted for a lowercase, underscored variable. Hopefully you will not use so many cookies as to find the name irritating.

The four functions:

zeta_cookie.set(name, value, expire, [ path ]);

name - the name of the cookie
value - the value of the cookie
expire - when the cookie expires; this can be a number (in days), a string (in days), or a Date object
path (optional) - the path to set the cookie to; should be like /topic or /post, not /board_name or /, as those values are prepended automagically

Return value: true or false, depending on if the cookie was set successfully (cookies with more than 4kb worth of data will fail)
zeta_cookie.get(name);

name - the name of the cookie

Return value: the value of the cookie (as a String)
zeta_cookie.del(name);

name - the name of the cookie

Return value: true or false, depending on if the cookie was deleted successfully (some older clients may give false)
zeta_cookie.path();

Return value: The path that is domain-specific to that board. For example, on any board without a custom domain, the path should be at least /board_name to prevent the cookie from being accessible on other boards on the same server. For any board with a custom domain, the path should be /.

This calculation is taken care of by default inside of the script. The path in set is reassigned to zeta_cookie.path() + path automatically. If that still doesn't make much sense, look at the source.. you'll get it. :P

The useful thing about this script is that it can be updated in case of a bug or something changing due to an update or anything like that and it will automatically fix itself in old code. I hope coders find this useful. :)
The Resource Board
Offline Profile Goto Top
 
RedBldSandman Apr 20 2010, 12:08 PM Post #2
Member Avatar
ZIPPY!

Posts:
482
Group:
Coding Staff
Member
#2,122
Joined:
Jan 25, 2009
Nice idea for making it easier for coders who don't like cookies :)

I was looking at it and the RegExp that's used in the path function wouldn't match something like s10.zetaboards.com would it and others with more than 1 digit in the server? Just something which may need to be tweaked? :)
Posted Image
"To iterate is human, to recurse divine."

Offline Profile Goto Top
 
Reid Apr 20 2010, 03:50 PM Post #3
Member Avatar
What? The land of the free? Whoever told you that was your enemy.

Posts:
1,790
Group:
Distinguished Coder
Member
#148
Joined:
Jul 20, 2008
Good catch! I didn't think about that. Updated. :)
The Resource Board
Offline Profile Goto Top
 
protego Jun 14 2010, 03:53 PM Post #4
Flash Guru

Posts:
59
Group:
Member
Member
#3,798
Joined:
Apr 24, 2010
Coding language
Everything
xD, thank you sooo much, I've been wasting an hour of my life each day coding tedious code to set cookies in such in order to see if somebody closed a news message yet. I love you man (you know what I mean)


Offline Profile Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Zetaboards Modifications · Next Topic »
Locked Topic

Track Topic · E-mail Topic Time: 7:49 PM Jul 10
Hosted for free by ZetaBoards · Privacy Policy