I’m trying to create a cookie that acts like a PHPSESSID but is JavaScript, I would just use PHP but i’m running node so that is impossible. The hope is that you get a 7 long character id that stays even when you reload the page and can’t be replicated. This is what I have tryed but it creates a new one instead of keeping it every time.
function randomString() {
//define a variable consisting alphabets in small and capital letter
var characters = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
//specify the length for the new string
var lenString = 7;
var randomstring = '';
//loop to select a new character in each iteration
for (var i=0; i<lenString; i++) {
var rnum = Math.floor(Math.random() * characters.length);
randomstring += characters.substring(rnum, rnum+1);
}
var thing = randomstring;
document.cookie = `${thing};expires=4000;`
}