網站登入 個人資訊儲存 方案

來源:互聯網
上載者:User

標籤:type   color   pat   設定   use   date   dex   code   new   

前情記錄:

這是關於前一段時間工作中網站的登陸資訊的小總結,以前也沒有想到要寫這個隨筆,是因為一個同事的一句話給了我很大的感觸,所以就決定要總結一下。

去年半年時間再做一個後台管理程式(ERP)網站的登陸、許可權等方面我負責,實現了登陸、許可權、緩衝丟失但不逾時自動重新登入、異地登陸登出等功能,還做了一個、一個官網的全部內容(這裡主要談登陸、個人資訊的儲存)。

但是自己沒有意識到自己用的什麼方式,在和同事聊模式的時候他說:erp中就是緩衝+資料庫的方式實現的。正所謂一舉驚醒夢中人,聽君一席話勝讀十年書,和別人交流(說與聽)真的能提升自己的認知。

一:簡單網站的個人資訊儲存方案:

採用cookie+sesion的方式判斷登陸狀態+個人資訊,登入時儲存兩者,並賦給相同到期時間,不排除session丟失的情況。

1:cookie中儲存簡單資訊用於頁面效果內容展示、判斷登陸狀態。

     js 擷取到cookie內容個人的基本資料和是否登陸,決定是否可以進入某些頁面、某些關鍵操作。

    cookie失效或者丟失則重新登入。

2:session用於後台判定登陸狀態session["userflag"] 登陸者["userid"] 

實際的操作回去判斷session的資訊有效性,判斷session失效後同時將cookie做到期處理,實現登陸狀態控制,並處理了session丟失的問題。

總結:簡答的前背景兩種標示判斷登陸狀態及資訊。

代碼:

function CookieHelper() {}//刪除cookieCookieHelper.prototype.deleteCookie = function (name) {    var date = new Date();    date.setTime(date.getTime() - 10000);    document.cookie = name + "=v; expires=" + date.toGMTString() + ";path=/";}//設定cookieCookieHelper.prototype.setCookie = function (name, value) {    //設定之前先刪除    this.deleteCookie(name);    //擷取目前時間     var date = new Date();    var expiresDays = 10;    //將date設定為10天以後的時間     date.setTime(date.getTime() + expiresDays * 24 * 3600 * 1000);    //cookie設定為10天后到期     document.cookie = name + "=" + value + "; expires=" + date.toGMTString() + ";path=/";    document.cookie}//擷取某一cookie key=valueCookieHelper.prototype.getCookie = function (name) {    var strCookie = document.cookie;    var arrCookie = strCookie.split("; ");    for (var i = 0; i < arrCookie.length; i++) {        var arr = arrCookie[i].split("=");        if (arr[0] == name) {            return arr[1];        }    }    return "";}//擷取cookie 類型 key=id=123&name=qwe&pwd=uioCookieHelper.prototype.getCookies = function (name) {    var strCookie = document.cookie;    var arrCookie = strCookie.split("; ");    for (var i = 0; i < arrCookie.length; i++) {        var arr = arrCookie[i].split("=");        if (arr[0] == name) {        return arrCookie[i].substring(arrCookie[i].indexOf("=") + 1)        }    }    return "";}//擷取所有cookieCookieHelper.prototype.getAllCookie = function (name) {    var strCookie = document.cookie;    var arrCookie = strCookie.split("; ");    if (arrcookie.length > 0) {        return arrCookie;    } else {        return "";    }}
CookieHelper

 

網站登入 個人資訊儲存 方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.