I am creating a PPC site. When timer counter is set to 0 code should automatically run query. If user close window and click again query should not trigger until again 30 secs are completed.
URL is set in database for users to visit with a column of hits. If hits are set to 0 or 1 by default (0) it will show. when a page is run it fetch record. Set two session of current URL & previous URL and update hits to 1. Both session are set similar initially. after thirty seconds when page loads again first current URL session is created ant it matches both session. If both session are different it will update hits to 2 by matching previous URL session and login ID.
Creating sessions of current URL and previous URL
$_SESSION['url']=$row['url'];
$_SESSION['previousURL']=$row['url'];
Javascript is used for timer
<script language="JavaScript" type="text/javascript">
function checklength(i) {
'use strict';
if (i < 10) {
i = "0" + i;
}
return i;
}
var minutes, seconds, count, counter, timer;
count = 30; //seconds
counter = setInterval(timer, 1000);
function timer() {
'use strict';
count = count - 1;
minutes = checklength(Math.floor(count / 60));
seconds = checklength(count - minutes * 60);
if (count < 0) {
clearInterval(counter);
return;
}
document.getElementById("countdown").innerHTML = 'Next refresh in ' + minutes + ':' + seconds + ' ';
if (count === 0) {
location.reload();
}
}
</script>
Actual output what i am getting in this case is if timer wont complete and user close window than by clicking again it fetch previous URL and set hits to 2.
What expected is that update query should only trigger when timer gets completed.