Jump to content

[SOLVED] Hit counter that resets weekly?


nfx

Recommended Posts

Each of my pages counts a hit when the page is loaded. So I have a counter that totals everything. What I'd like is to make it count a hit twice when a page is loaded, one for the original counter and one that resets back to zero every 7 days. The only part I don't know how to do is to get it to reset.

 

I mean right now the total hit counter isn't very useful. Pages that have been on there for a couple years are going to be leaps and bounds higher than recently added pages. I just want a more relative counter.

Link to comment
Share on other sites

create a "cron job" that runs once every seven days.

 

then just create a query such as:

UPDATE `table_name` SET counter = '0'

 

Ah, thank you. I've never used CRON so this helps a lot. Should be everything I need, thanks.

Link to comment
Share on other sites

So I just create a php file with nothing but the code to connect to the database and to set each counter to 0? And the cron command is the url to the php file? Sorry, I know I already checked this off as solved, just want to make sure before I ruin something.

Link to comment
Share on other sites

Yes I'm using cPanel.

 

If I wanted it to run every Sunday at 2am, would my crontab be?

 

* 02 * * sun /somefolder/script.php

 

Or is it not that simple?

 

You would need to use the PHP CLI command for UNIX to accomplish that. Google PHP CLI CRON for examples.

 

EDIT:

For your script it would look like

* 2 * * 0 /usr/bin/php -f /home/phpscripts/yourscript.php

 

Given that php is installed to /usr/bin/

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.