View Full Version : Counter continuing from page to page?

08-25-2008, 03:07 PM

I would like to reproduce the counter present in the header of the page http://www.ensembleverslavenir.ca/fr/accueil/

The calculation code looks easy (check below), but there has a cookies system (or an ASP code that I would like to convert in PHP), which allow the counter to continue from page to page (idem if you did a page refresh).

Perhaps an ID is created whenever the browser opens a session on the site?
The counter restarts at zero when the browser leaves the site.

Would you have an idea of how to re-encode the same system but in PHP?
Thanks a lot :)

<div class="counter"><span id="counter">8.15</span> tonnes</strong> de gaz à effet de serre ont été émis au Québec depuis le début de votre visite.</div>

<script language="JavaScript" type="text/javascript">
var sTotal = 0;
function gazCount(){
document.getElementById("counter").innerHTML = r2(sTotal*2.91);
//document.getElementById("counter").innerHTML = r2(sTotal);
setTimeout("gazCount();", 100);
function r2(n){
ans = n * 1000
ans = Math.round(ans /10) + ""
while (ans.length < 3) {ans = "0" + ans}
len = ans.length
ans = ans.substring(0,len-2) + "." + ans.substring(len-2,len)
return ans

08-25-2008, 03:16 PM
Would you have an idea of how to re-encode the same system but in PHP?
The counter is done with Javascript, and it is a dynamic script... PHP only codes "static", I'll say, scripts. You can't make animations with PHP for example.

08-26-2008, 01:15 AM
I have a script that usign php/javascript to get the current server's time with PHP but then make an automatic counter so that it keeps going up using javascript.

I also have one that will retrieve a timestamp from the database, find out how many seconds it is until that, turn it into hh:mm:ss format, and do a countdown, and at the end when it reaches 0:00:00 it refreshes the page.

Would that help atall?