Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
How to make a cookie, that is random, and won't change once the user comes back (can't be PHPSESSID= because im running node.js)

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;`
}  

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Ok so I just tryed the domain=https://example.com/; and that worked, maybe theres a better way feel free to post other answers! fullcode,

  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;domain=https://eez.penguinpowers.repl.co;`
}  
about 4 years ago · Juan Pablo Isaza Report

0

express-session, It's basically PHPSessionID but for Express.js
(link)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!