/    Sign up×
Community /Pin to ProfileBookmark

auto resetting counter for website

Hi

I’m looking for a counter that has the following features.

[LIST=1]

  • [*]

    Starts at midnight.


  • [*]

    adds to counter in increments of several seconds (ex. 32 seconds)


  • [*]

    starts again from zero the following day at midnight


  • [*]

    has to be adjustable to time zone


  • [/LIST]

    this counter will e added to a WordPress website. Does anyone have any ideas??

    Thanks

    to post a comment
    PHP

    4 Comments(s)

    Copy linkTweet thisAlerts:
    @mjunkerauthorOct 29.2017 — for #2 when I say "adds to counter in increments of several seconds (ex. 32 seconds)" i mean a 1. so the counter counts up every 32 seconds. Sorry for the confusion.
    Copy linkTweet thisAlerts:
    @rootOct 29.2017 — I have never heard of wanting to restart a site counter at midnight before, so I suppose what you can do is use a piece of BASH script to run a PHP script via a CronJob that does the reset, that can be set to run once at midnight.

    The script could wipe out a database field value of the page count.

    Then all you need worry about is code for reading the current count.
    Copy linkTweet thisAlerts:
    @NogDogOct 30.2017 — If I'm understanding it correctly, maybe something like:
    [code=php]
    function counter($timezone, $intervalInSeconds)
    {
    date_default_timezone_set($timezone);
    $start = strtotime(date('Y-m-d').'T00:00:00');
    return floor((time() - $start) / $intervalInSeconds);
    }

    // sample usage:
    echo counter('America/New_York', 32);
    [/code]
    Copy linkTweet thisAlerts:
    @rootOct 30.2017 — IMHO, I think this is a bit of a combination, if the increment is every 32 seconds by 1, then this would be a server script being invoked by a CronJob to call a BASH Script that then runs a PHP script to do the insert and updates and also be responsible for wiping the database at midnight.

    When a page is requested, an AJAX script could every 32 seconds from the request_time poll the server via another server side to return that count.
    ×

    Success!

    Help @mjunker spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.2,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,
    )...