search

Home  >  Q&A  >  body text

javascript - 网页 下次自动登录如何实现

用cookie 和JS 实现下次自动登录 哪位大大 有例子 贴身上来 学习学习

阿神阿神2902 days ago587

reply all(3)I'll reply

  • ringa_lee

    ringa_lee2017-04-10 14:31:42

    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的时间

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-10 14:31:42

    转载自 coolshell 耗子哥的:

    你会做Web上的用户登录功能吗

    reply
    0
  • 高洛峰

    高洛峰2017-04-10 14:31:42

    这不是js可以搞定的. 安全方面的事情都必须后台做, 当然你要是用node做后台就可以用js搞定了....

    reply
    0
  • Cancelreply