cookies ultima visita

    0

    5

    ismael zian

    If the user visits the page more than once within a certain period of time, the "Ultima visita" value will be incremented for each visit.

    Shortcut: cookies_ultimavisita

    var cookie = document.cookie.split("; ");//haces split
    
    for (var i in cookie) {
        item = cookie[i].split("=");// y otravez
    
      if (item[0] == "lastvisit"){
        lastvisit = item[1];//asi pillas la cookie
      }
    }
    
    if (lastvisit != undefined)//si esta definida imprimes
      document.getElementById("lastvisit").innerHTML = "Ultima visita: " + lastvisit;
    
    var data = new Date();//creas una data
    data.setFullYear(data.getFullYear() + 1);//para que expire en 1 aΓ±o
    
    var data_actual = new Date();
    document.cookie = "lastvisit=" + data_actual.toLocaleString() + ";expires=" + data.toUTCString() + ";";
    //creas una cookie con un nombre + valor + expiracion(que es la data de antes)
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.