Countdown Cookies Kill

so. I have this so far.

function setCookie(cname,cvalue,exdays)
{
var d = new Date();
d.setTime(d.getTime()+(exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function getCookie(cname)
{
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i {
var c = ca[i].trim();
if (c.indexOf(name)==0) return c.substring(name.length,c.length);
}
return "";
}

//check existing cookie
cook=getCookie("my_cookie");

if(cook==""){
//cookie not found, so set seconds=60
var seconds = 60;
}else{
seconds = cook;
console.log(cook);
}

function secondPassed() {
var minutes = Math.round((seconds - 30)/60);
var remainingSeconds = seconds % 60;
if (remainingSeconds < 10) {
remainingSeconds = "0" + remainingSeconds; 
}
//store seconds to cookie
setCookie("my_cookie",seconds,60*1000); //here 5 is expiry days

document.getElementById('countdown').innerHTML = minutes + ":" +    remainingSeconds;
if (seconds == 0) {
    clearInterval(countdownTimer);
    document.getElementById('countdown').innerHTML = "<? uhpn($mysqli); ?>";
} else {    
    seconds--;
}
}

var countdownTimer = setInterval(secondPassed, 1000);

Witch is a timer. I just need to make that it would delete the cookie after the timer is done counting, Or I need to make it refresh to to 60 seconds again. I tryed adding var seconds = 60; So it would set the seconds to 60 when its done again
but so far no luck, and I tryed to delete cookies after 60 secconds (so when the counter is done counting seconds, it would delete the cookies and move on, so after refresh it would go again. And I tryed to kill the cookies when it hits complete with setCookie(“my_cookie”,-1); (as I read, I understood that if you set the cookie exp date to a minus it would automatically remove itself.) So I ran into this one now. Help me if someone can.

In the block you call clearInterval, add setCookie(‘my_cookie’, ‘’, -1). That should do it.

In your pasted code, your for loop is garbled.

1 Like

Yep, my php code ends the timer. It doesnt go again. How can I fix that?


sec_session_start();

function uhpn($mysqli) {
if ($stmt = $mysqli->prepare(“UPDATE members SET health = health+1 WHERE id = ? LIMIT 1”)) {
$user_id = $_SESSION[‘user_id’];
$stmt->bind_param(‘i’, $user_id);
// check if the query did execute and that it affected a row
if ($stmt->execute() && $mysqli->affected_rows > 0) {
exit;
}
}
return false;
}