用cookie 和JS 实现下次自动登录 哪位大大 有例子 贴身上来 学习学习
转载自 coolshell 耗子哥的:
你会做Web上的用户登录功能吗
function setCookie(key,value,options){
var options = options||{};
if(options.hour){
var today = new Date();
var expire = new Date();
expire.setTime(today.getTime() + options.hour * 3600000);
}
window.document.cookie =
key + "=" + value
+ (options.path ? "; path=" + options.path : "")
+ (options.hour ? "; expires=" + expire.toGMTString() : "")
+ (options.domain ? "; domain=" + options.domain : "");
return this;
}
function getCookie(key){
var reg = new RegExp("(^| )" + key + "=([^;]*)(;|\x24)"),
result = reg.exec(document.cookie);
if(result){
return result[2]||null;
}
}
然后设置cookie的时间
这不是js可以搞定的. 安全方面的事情都必须后台做, 当然你要是用node做后台就可以用js搞定了....