Cookie的有效期限设置为分钟而不是几天

时间:2018-12-16 21:08:19

标签: javascript wordpress cookies

我正在为Wordpress使用一个免费插件,不幸的是,尽管它是一个非常有用且功能强大的插件,但笔者似乎并不是很主动。

所以我遇到了一个问题,例如在插件的配置中,它允许您在几天内设置Cookie的过期时间,但是我想知道是否有可能,因此我可以修改代码并将其设置为分钟或秒。

所以我进入了插件文件,发现我认为是设置cookie的实际代码(对不起,但我不是程序员,所以我无法真正分辨出这段代码的作用),所以我我想知道是否有人可以确认我,那是否是控制cookie到期的实际代码,以及是否可以更改它来完成我需要的工作。

这是代码:

!function(e){var n=!1;if("function"==typeof define&&define.amd&&(define(e),n=!0),"object"==typeof exports&&(module.exports=e(),n=!0),!n){var o=window.Cookies,t=window.Cookies=e();t.noConflict=function(){return window.Cookies=o,t}}}(function(){function e(){for(var e=0,n={};e<arguments.length;e++){var o=arguments[e];for(var t in o)n[t]=o[t]}return n}function n(o){function t(n,r,i){var c;if("undefined"!=typeof document){if(arguments.length>1){if(i=e({path:"/"},t.defaults,i),"number"==typeof i.expires){var a=new Date;a.setMilliseconds(a.getMilliseconds()+864e5*i.expires),i.expires=a}i.expires=i.expires?i.expires.toUTCString():"";try{c=JSON.stringify(r),/^[\{\[]/.test(c)&&(r=c)}catch(f){}r=o.write?o.write(r,n):encodeURIComponent(String(r)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),n=encodeURIComponent(String(n)),n=n.replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent),n=n.replace(/[\(\)]/g,escape);var s="";for(var p in i)i[p]&&(s+="; "+p,i[p]!==!0&&(s+="="+i[p]));return document.cookie=n+"="+r+s}n||(c={});for(var d=document.cookie?document.cookie.split("; "):[],u=/(%[0-9A-Z]{2})+/g,l=0;l<d.length;l++){var C=d[l].split("="),g=C.slice(1).join("=");'"'===g.charAt(0)&&(g=g.slice(1,-1));try{var m=C[0].replace(u,decodeURIComponent);if(g=o.read?o.read(g,m):o(g,m)||g.replace(u,decodeURIComponent),this.json)try{g=JSON.parse(g)}catch(f){}if(n===m){c=g;break}n||(c[m]=g)}catch(f){}}return c}}return t.set=t,t.get=function(e){return t.call(t,e)},t.getJSON=function(){return t.apply({json:!0},[].slice.call(arguments))},t.defaults={},t.remove=function(n,o){t(n,"",e(o,{expires:-1}))},t.withConverter=n,t}return n(function(){})});

预先感谢

1 个答案:

答案 0 :(得分:0)

今天我再试一次,正如charlietfl所说,如果您使用小数,它会起作用。我的错误是我尝试使用(昏迷)而不是进行十进制。 (点)。

谢谢