{"id":633,"date":"2008-11-12T11:11:04","date_gmt":"2008-11-12T03:11:04","guid":{"rendered":"http:\/\/fdream.net\/blog\/article\/633.aspx"},"modified":"2008-11-12T11:11:33","modified_gmt":"2008-11-12T03:11:33","slug":"MooTools%e7%9a%84Cookie%e7%b1%bb%e5%a4%aa%e2%80%9c%e8%87%aa%e4%bd%9c%e8%81%aa%e6%98%8e%e2%80%9d%e4%ba%86","status":"publish","type":"post","link":"https:\/\/fdream.net\/blog\/article\/633","title":{"rendered":"MooTools\u7684Cookie\u7c7b\u592a\u201c\u81ea\u4f5c\u806a\u660e\u201d\u4e86"},"content":{"rendered":"<p>\u6ca1\u6ce8\u610f\u5230MooTools\u7684Cookie\u7c7b\u5728\u5199\u7684\u65f6\u5019\u81ea\u5df1\u505a\u4e86\u4e00\u6b21encode\uff0c\u5728\u8bfb\u7684\u65f6\u5019\u505a\u4e86\u4e00\u6b21decode\uff0c\u5728\u4e00\u822c\u7684\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4e2a\u4e0d\u4f1a\u6709\u4ec0\u4e48\u95ee\u9898\u3002\u4f46\u662f\u60f3\u4e00\u4e0b\u7279\u6b8a\u7684\u60c5\u51b5\uff0c\u5982\u679c\u4f60\u5728\u670d\u52a1\u5668\u7aef\u5199Cookie\u7684\u65f6\u5019\u6ca1\u6709encode\uff0c\u90a3\u4e48\u8bfb\u7684\u65f6\u5019\u662f\u4e0d\u662f\u4f1a\u4e71\u6389\uff1f\u5f53\u7136\u4e86\uff0c\u670d\u52a1\u5668\u7aef\u4ee3\u7801\u5199Cookie\u4e00\u822c\u8fd8\u662f\u4f1aencode\u7684\u3002\u4f46\u662f\u95ee\u9898\u662f\u8fd9\u6837\u7684\uff0c\u5982\u679c\u4f60\u8981\u5199\u4e00\u4e2a\u5f88\u957f\u7684Cookie\uff0c\u4e2d\u95f4\u6709\u5f88\u591a\u5185\u5bb9\uff0c\u4f60\u5148\u628a\u8fd9\u4e9b\u5185\u5bb9\u90a3\u4e2aencode\uff0c\u7136\u540e\u7528$\u4f5c\u4e3a\u5206\u9694\u7b26\u628a\u8fd9\u4e9b\u9879\u8fde\u63a5\u8d77\u6765\uff0c\u518d\u7528\u670d\u52a1\u5668\u7aef\u4ee3\u7801\u5199\u5165\u5230Cookie\u91cc\u9762\u3002\u597d\uff0c\u4f60\u73b0\u5728\u7684Cookie\u7684\u503c\u53ef\u80fd\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p><pre lang=\"html\">\n\/\/ \u8fd9\u4e2acookie\u7684\u5185\u5bb9\u6709\u4e09\u9879\uff0c\u5206\u522b\u4e3a\uff1a\n\/\/ Fdream\u2014\u2014decode\u4e4b\u540e\u4e3a\u2014\u2014Fdream\n\/\/ http%3A%2F%2Ffdream.net\u2014\u2014decode\u4e4b\u540e\u4e3a\u2014\u2014http:\/\/fdream.net\n\/\/ %25%25%24%24\u2014\u2014decode\u4e4b\u540e\u4e3a\u2014\u2014%%$$\nyoukey=Fdream$http%3A%2F%2Ffdream.net$%25%25%24%24\n<\/pre>\n<\/p>\n<p>\u8fd9\u4e9b\u662f\u670d\u52a1\u5668\u7aef\u5199\u8fdb\u53bb\u7684\uff0c\u73b0\u5728\u6211\u4eec\u7528MooTools\u7684Cookie\u7c7b\u6765\u8bfb\uff0c\u90a3\u4e48\u8fd4\u56de\u7684\u5185\u5bb9\u5c06\u662f\uff1a<\/p>\n<pre lang=\"html\">\nyoukey=Fdream$http:\/\/fdream.net$%%$$\n<\/pre>\n<\/p>\n<p>\u975e\u5e38\u9057\u61be\u7684\u662f\uff0c\u6211\u4eec\u7684\u5206\u9694\u7b26$\u8fd9\u4e2a\u65f6\u5019\u5df2\u7ecf\u5b8c\u5168\u88ab\u6df7\u6dc6\u4e86\u2014\u2014\u6700\u540e\u90a3\u4e24\u4e2a$\u4e0d\u662f\u6211\u4eec\u7684\u5206\u9694\u7b26\uff01<\/p>\n<p>\u600e\u4e48\u529e\uff1f\u6539\u5206\u9694\u7b26\uff1f\u9ebb\u70e6\uff0c\u8bf4\u4e0d\u5b9a\u4ee5\u540e\u8fd8\u662f\u4f1a\u78b0\u5230\u7c7b\u4f3c\u7684\u95ee\u9898\u3002\u4e0d\u5982\u76f4\u63a5\u6539MooTools\u7684Cookie\u7c7b\u6765\u5f97\u723d\u5feb\uff0c\u4fee\u6539\u7684\u90e8\u5206\u89c1\u4e0b\u9762\u7684\u6ce8\u91ca\uff1a<\/p>\n<p><pre lang=\"javascript\">\nvar Cookie = new Class({\n\n    Implements: Options,\n\n    options: {\n        path: false,\n        domain: false,\n        duration: false,\n        secure: false,\n        \/\/ \u65b0\u6dfb\u52a0\u7684\u9009\u9879\uff0c\u8bfb\u53d6\u65f6\u662f\u5426decode\uff0c\n        \/\/ \u4e3a\u4fdd\u6301\u548cMooTools\u7684\u539f\u6765\u884c\u4e3a\u4e00\u81f4\uff0c\u9ed8\u8ba4\u4e3atrue\n        decode: true,\n        \/\/ \u65b0\u6dfb\u52a0\u7684\u9009\u9879\uff0c\u5199\u5165\u662f\u662f\u5426encode\uff0c\n        \/\/ \u4e3a\u4fdd\u6301\u548cMooTools\u7684\u539f\u6765\u884c\u4e3a\u4e00\u81f4\uff0c\u9ed8\u8ba4\u4e3atrue\n        encode: true,\n        document: document\n    },\n\n    initialize: function(key, options) {\n        this.key = key;\n        this.setOptions(options);\n    },\n\n    write: function(value) {\n        \/\/ \u5982\u679c\u4f7f\u7528encode\uff0c\u5bf9value\u8fdb\u884cencode\uff0c\u5426\u5219\u4e0dencode\n        if (this.options.encode) value = encodeURIComponent(value);\n        if (this.options.domain) value += '; domain=' + this.options.domain;\n        if (this.options.path) value += '; path=' + this.options.path;\n        if (this.options.duration) {\n            var date = new Date();\n            date.setTime(date.getTime() + this.options.duration * 24 * 60 * 60 * 1000);\n            value += '; expires=' + date.toGMTString();\n        }\n        if (this.options.secure) value += '; secure';\n        this.options.document.cookie = this.key + '=' + value;\n        return this;\n    },\n\n    read: function() {\n        var value = this.options.document.cookie.match('(?:^|;)\\\\s*' + this.key.escapeRegExp() + '=([^;]*)');\n        \/\/ \u9ed8\u8ba4decode\uff0c\u5426\u5219\u4e0ddecode\n        if (this.options.decode) {\n            return (value) ? decodeURIComponent(value[1]) : null;\n        }\n        else {\n            return (value) ? value[1] : null;\n        }\n    },\n\n    dispose: function() {\n        new Cookie(this.key, $merge(this.options, { duration: -1 })).write('');\n        return this;\n    }\n\n});\n\nCookie.write = function(key, value, options){\n    return new Cookie(key, options).write(value);\n};\n\n\/\/ \u52a0\u4e86\u4e2aoptions\u53c2\u6570\uff0c\u4ece\u800c\u53ef\u4ee5\u8bbe\u7f6e\u662f\u5426\u4f7f\u7528decode\n\/\/ \u548c\u8be5\u7c7b\u4e2d\u5176\u4ed6\u53c2\u6570\u4f7f\u7528\u7684\u65b9\u6cd5\u4e00\u81f4\nCookie.read = function(key, options) {\n    return new Cookie(key, options).read();\n};\n\nCookie.dispose = function(key, options){\n    return new Cookie(key, options).dispose();\n};\n<\/pre>\n<\/p>\n<p>\u6700\u540e\uff0c\u8fd9\u4e2aCookie\u7c7b\u8fd8\u6709\u4e00\u4e2a\u6bd4\u8f83\u4e0d\u723d\u7684\u5730\u65b9\u662f\uff0c\u8fd9\u91cc\u5199Cookie\u7684\u8fc7\u671f\u65f6\u95f4\u662f\u4ee5\u5929\u4e3a\u5355\u4f4d\u7684\uff0c\u5982\u679c\u4f60\u53ea\u60f3\u4fdd\u5b58\u51e0\u4e2a\u5c0f\u65f6\uff0c\u9700\u8981\u4f20\u5165\u5c0f\u4e8e1\u7684\u5c0f\u6570\uff0c\u55ef\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6ca1\u6ce8\u610f\u5230MooTools\u7684Cookie\u7c7b\u5728\u5199\u7684\u65f6\u5019\u81ea\u5df1\u505a\u4e86\u4e00\u6b21encode\uff0c\u5728\u8bfb\u7684\u65f6\u5019\u505a\u4e86\u4e00\u6b21decode\uff0c\u5728\u4e00\u822c\u7684\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4e2a\u4e0d\u4f1a\u6709\u4ec0\u4e48\u95ee\u9898\u3002\u4f46\u662f\u60f3\u4e00\u4e0b\u7279\u6b8a\u7684\u60c5\u51b5\uff0c\u5982\u679c\u4f60\u5728\u670d\u52a1\u5668\u7aef\u5199Cookie\u7684\u65f6\u5019\u6ca1\u6709encode\uff0c\u90a3\u4e48\u8bfb\u7684\u65f6\u5019\u662f\u4e0d\u662f\u4f1a\u4e71\u6389\uff1f\u5f53\u7136\u4e86\uff0c\u670d\u52a1\u5668\u7aef\u4ee3\u7801\u5199Cookie\u4e00\u822c\u8fd8\u662f\u4f1aencode\u7684\u3002\u4f46\u662f\u95ee\u9898\u662f\u8fd9\u6837\u7684\uff0c\u5982\u679c\u4f60\u8981\u5199\u4e00\u4e2a\u5f88\u957f\u7684Cookie\uff0c\u4e2d\u95f4\u6709\u5f88\u591a\u5185\u5bb9\uff0c\u4f60\u5148\u628a\u8fd9\u4e9b\u5185\u5bb9\u90a3\u4e2aencode\uff0c\u7136\u540e\u7528$\u4f5c\u4e3a\u5206\u9694\u7b26\u628a\u8fd9\u4e9b\u9879\u8fde\u63a5\u8d77\u6765\uff0c\u518d\u7528\u670d\u52a1\u5668\u7aef\u4ee3\u7801\u5199\u5165\u5230Cookie\u91cc\u9762\u3002\u597d\uff0c\u4f60\u73b0\u5728\u7684Cookie\u7684\u503c\u53ef\u80fd\u662f\u8fd9\u6837\u7684\uff1a \/\/ \u8fd9\u4e2acookie\u7684\u5185\u5bb9\u6709\u4e09\u9879\uff0c\u5206\u522b\u4e3a\uff1a \/\/ Fdream\u2014\u2014decode\u4e4b\u540e\u4e3a\u2014\u2014Fdream \/\/ http%3A%2F%2Ffdream.net\u2014\u2014decode\u4e4b\u540e\u4e3a\u2014\u2014http:\/\/fdream.net \/\/ %25%25%24%24\u2014\u2014decode\u4e4b\u540e\u4e3a\u2014\u2014%%$$ youkey=Fdream$http%3A%2F%2Ffdream.net$%25%25%24%24 \u8fd9\u4e9b\u662f\u670d\u52a1\u5668\u7aef\u5199\u8fdb\u53bb\u7684\uff0c\u73b0\u5728\u6211\u4eec\u7528MooTools\u7684Cookie\u7c7b\u6765\u8bfb\uff0c\u90a3\u4e48\u8fd4\u56de\u7684\u5185\u5bb9\u5c06\u662f\uff1a youkey=Fdream$http:\/\/fdream.net$%%$$ \u975e\u5e38\u9057\u61be\u7684\u662f\uff0c\u6211\u4eec\u7684\u5206\u9694\u7b26$\u8fd9\u4e2a\u65f6\u5019\u5df2\u7ecf\u5b8c\u5168\u88ab\u6df7\u6dc6\u4e86\u2014\u2014\u6700\u540e\u90a3\u4e24\u4e2a$\u4e0d\u662f\u6211\u4eec\u7684\u5206\u9694\u7b26\uff01 \u600e\u4e48\u529e\uff1f\u6539\u5206\u9694\u7b26\uff1f\u9ebb\u70e6\uff0c\u8bf4\u4e0d\u5b9a\u4ee5\u540e\u8fd8\u662f\u4f1a\u78b0\u5230\u7c7b\u4f3c\u7684\u95ee\u9898\u3002\u4e0d\u5982\u76f4\u63a5\u6539MooTools\u7684Cookie\u7c7b\u6765\u5f97\u723d\u5feb\uff0c\u4fee\u6539\u7684\u90e8\u5206\u89c1\u4e0b\u9762\u7684\u6ce8\u91ca\uff1a var Cookie = new Class({ Implements: Options, options: { path: false, domain: false, duration: false, secure: false, \/\/ \u65b0\u6dfb\u52a0\u7684\u9009\u9879\uff0c\u8bfb\u53d6\u65f6\u662f\u5426decode\uff0c \/\/ \u4e3a\u4fdd\u6301\u548cMooTools\u7684\u539f\u6765\u884c\u4e3a\u4e00\u81f4\uff0c\u9ed8\u8ba4\u4e3atrue decode: true, \/\/ \u65b0\u6dfb\u52a0\u7684\u9009\u9879\uff0c\u5199\u5165\u662f\u662f\u5426encode\uff0c \/\/ \u4e3a\u4fdd\u6301\u548cMooTools\u7684\u539f\u6765\u884c\u4e3a\u4e00\u81f4\uff0c\u9ed8\u8ba4\u4e3atrue encode: true, document: document }, initialize: function(key, options) { this.key = key; this.setOptions(options); }, &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[120,104,328],"class_list":["post-633","post","type-post","status-publish","format-standard","hentry","category-coding","tag-AJAX","tag-JavaScript","tag-mootools"],"views":10402,"_links":{"self":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/633","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/comments?post=633"}],"version-history":[{"count":0,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/posts\/633\/revisions"}],"wp:attachment":[{"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/media?parent=633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/categories?post=633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fdream.net\/blog\/wp-json\/wp\/v2\/tags?post=633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}