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

120
Views
old cookies not getting deleted with js via php

I have the below PHP code which via JS should:

  1. expire old cookies except ones with the name 'abc'
  2. create a new cookie

It does the second part very well. It does output the name of the old cookies (currcname) to the console. It does not expire the old cookies.

         echo "<script type='text/javascript'>
                var currcookies = document.cookie.split(';');
                var currcname = '';
                for(var i = 0; i < currcookies.length; i++) {
                    currcname=currcookies[i].split('=')[0] ;
                    console.log(currcname)
                    if(currcname != 'abc'){
                        document.cookie = currcname + ' = ; expires = Thu, 01 Jan 1970 00:00:00 GMT';
                    }           
                }
                
                var cookieName = '".$cookname."';
                var cookieValue = '".$hiddenq."';
                var myDate = new Date();
                myDate.setDate(myDate.getDate() + 1);
                document.cookie = cookieName + '=' + cookieValue + ';expires=' + myDate + ';path=/';
               </script>";

Any ideas?

about 4 years ago · Juan Pablo Isaza
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!