Setting a cookie to put a whole JSON into a cookie instead of putting it in a separate place affects efficiency.
var Cookies = {};
/**
* Set Cookies
*/
var Cookies = {};
/**
* Set Cookies
*/
Cookies.set = function (name, value,hours) {
var argv = arguments;
var argc = arguments.length;
var ms = hours * 3600 * 1000;
Date.settime (Date.gettime () + ms);
var expires=date.togmtstring ();
var path = (argc > 3)? ARGV[3]: '/';
var domain = (argc > 4)? ARGV[4]: null;
var secure = (argc > 5)? ARGV[5]: false;
Document.cookie = name + "=" + Escape (value) +
((expires = = null)? "" : ("; Expires= "+ exp.togmtstring ())) +
(Path = = null)? "" : ("; Path= "+ path) +
(domain = = null)? "" : ("; domain= "+ domain") +
(Secure = = True)? "; Secure ":");
};
/**
* Read cookies
*/
Cookies.get = function (name) {
var arg = name + "=";
var alen = Arg.length;
var clen = document.cookie.length;
var i = 0;
var j = 0;
while (I < Clen) {
j = i + Alen;
if (Document.cookie.substring (i, j) = = arg)
Return Cookies.getcookieval (j);
i = Document.cookie.indexOf ("", I) + 1;
if (i = = 0)
Break
}
return null;
};
/**
* Clear Cookies
*/
Cookies.clear = function (name) {
if (cookies.get (name)) {
var expdate = new Date ();
Expdate.settime (Expdate.gettime ()-(86400 * 1000 * 1));
Cookies.set (Name, "", expdate);
}
};
Cookies.getcookieval = function (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr = =-1) {
Endstr = Document.cookie.length;
}
Return unescape (document.cookie.substring (offset, endstr));
};
Convert JSON to string:
var data = {
' Vipflag ': ' 1 ',
' Usertype ': ' 11 ',
' UID ': ' 12345 ',
' token ': ' 654 ',
' Thumb ': ' 687.jpg ',
' StartTime ': ',
' Pretime ': ',
' Nickname ': '%u68ee%u6797%u91ce%u5c0f%u5b50 ',
' EndTime ': ',
' Date ': ' 20150625152139 ',
' Channelid ': ' 100218 ',
' Auctiontime ': ',
' ActivityID ': '
};
var obj =json.stringify (data);
JS settings Cookie Read in PHP (Master trick)