I found this https://github.com/inorganik/CountUp.js
As my knowledge of javascript is very weak, i am asking for your help to store the counter result local, then display it on the user`s browser...

   var options = {
      useEasing : true, 
      useGrouping : true, 
      separator : ',', 
      decimal : '.', 
      prefix : '', 
      suffix : '' 
    };
    var demo = new CountUp("myTargetElement", 0, 9999999, 0, 998.9, options);
    demo.start();

Like this, it will count forever ( i think )

Many Thanks!

Nobody ?:(

What exactly are you having trouble with? What vaule do you want to store (the start or end value of the counter maybe)?
This script really is simple to use: set up a div you want to hold the counter, add the CountUp js file and call the method. Clearly you want to do something more than that. A deeper explanation would help us out.

I agree. A better explanation and you would get useful answers.

Well i want to store the counted value + keep counting on every times the page is visited, so if the count now is 100, you visit apage.php/html, counter keeps counting, so let`s say the number has reached 350, then somebody else visits the page, again, the counter keeps counting from the last number(350) + ....

Now do you understand what i am searching for?

Member Avatar for diafol

I don't think js is the way to go. You need a server-side solution. Javascript just works on the local (client) machine - nothing is passed to the server as a rule (unless via Ajax).

Are you using server-side tech like PHP, ASP, Java, NodeJS ? If so, which one. This would be a trivial piece of code - a handful of lines maybe.

I am using PHP, Here is my website: liveguardmu.com
As you can see i have a counter there, i made it somehow, but i don`t like it...
Right now current count is stored into a .txt file, i reach it on every client, and count again via PHP. Please give me ideas/examples -_-

Member Avatar for diafol

Sorry can't see any counter on there. Anyway, depends on what you need - unique counts or total counts

Check Again please, on the right sidebar.
Totsal counts, i will display the total counts.
I will explain again:

You visit my page, counter starts, as long as you stay on my page counter keeps counting, but in the mean time another person visits my page, the counter continues to count from the last number that the counter was while you are on my page. Does this make any sense?

Member Avatar for diafol

I saw the counter - Threats Blocked?

It just seems to be counting up every second or so. I can't see what purpose this has within the context of the page.

What happens if you have concurrent visitors? E.g. 20 visitors at a time? Do you update 20 times per second?

Are you updating a text file on the server every second? If so, every client on your site will be forcing an increment, won't they?

I'm really at a loss as to what you're trying to show. I understand you want to increment the counter while your page is in somebody's browser - but I'm not sure why.

Yes, you are so right. I think at the moment i am overclocking my webhost :)) haha. Anyway, let me reformulate:

-The counter should count in the background independent
-The counter show display the same result to all visitors

Sounds better?

Member Avatar for diafol

How about a start time having an offset, e.g.

$time = time();
$offset = 27485997; //or whatever
$time += $offset;

Then in your html page

<script>
    var startTime = <?=$time?>;
    //then increment a standard setInterval event to incement the time every second 
</script>

This means everybody gets the current time + offset (offset could be a negative value). Then you don't have to store anything. Pretty pointless, but is that what you want?

Yeah it will do for now, thank you :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.