nfx Posted January 16, 2009 Share Posted January 16, 2009 I'm trying to make a hit counter that resets back to 0 every 7 days, to show which page is the hottest that week. How do I go about making a timer like that? Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/ Share on other sites More sharing options...
Maq Posted January 16, 2009 Share Posted January 16, 2009 Could you be a little more explanatory? Like what you're counting? Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/#findComment-738595 Share on other sites More sharing options...
nfx Posted January 16, 2009 Author Share Posted January 16, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/#findComment-738602 Share on other sites More sharing options...
premiso Posted January 16, 2009 Share Posted January 16, 2009 CRON job on UNIX or Scheduled task on Windows. Create a script that runs once a week and have it wipe the hit counter clean. If you want more help post some code....something cause right now your question is way too vague. Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/#findComment-738609 Share on other sites More sharing options...
The Little Guy Posted January 16, 2009 Share Posted January 16, 2009 create a "cron job" that runs once every seven days. then just create a query such as: UPDATE `table_name` SET counter = '0' Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/#findComment-738610 Share on other sites More sharing options...
nfx Posted January 16, 2009 Author Share Posted January 16, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/#findComment-738622 Share on other sites More sharing options...
Maq Posted January 16, 2009 Share Posted January 16, 2009 Cron is relatively easy to use, just specify time and script you want to execute. The hardest part is the time-format. Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/#findComment-738628 Share on other sites More sharing options...
The Little Guy Posted January 16, 2009 Share Posted January 16, 2009 When you create your cron job, make sure you place the php file that will run out side of the root directory, or you could have some major issues. Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/#findComment-738638 Share on other sites More sharing options...
nfx Posted January 16, 2009 Author Share Posted January 16, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/#findComment-738665 Share on other sites More sharing options...
Maq Posted January 16, 2009 Share Posted January 16, 2009 You need to go to your crontab and edit it. At the CLI type (i think): crontab -i to edit your cron and add in the time parameters and the path to the script you want executed. Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/#findComment-738680 Share on other sites More sharing options...
The Little Guy Posted January 16, 2009 Share Posted January 16, 2009 are you using "cPanel"? Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/#findComment-738681 Share on other sites More sharing options...
nfx Posted January 16, 2009 Author Share Posted January 16, 2009 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 would the path have to be /home/<user>/public_html/somefolder/script.php? Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/#findComment-738688 Share on other sites More sharing options...
premiso Posted January 16, 2009 Share Posted January 16, 2009 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/ Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/#findComment-738690 Share on other sites More sharing options...
Maq Posted January 16, 2009 Share Posted January 16, 2009 Or is it not that simple? Yes it is as simple as that. Although I'm not sure if your time is correct. Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/#findComment-738692 Share on other sites More sharing options...
nfx Posted January 16, 2009 Author Share Posted January 16, 2009 So... * 2 * * 0 /usr/bin/php -q /home/<user>/public_html/somefolder/script.php Should do every Sunday a 2am. Hopefully that's right? Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/#findComment-738699 Share on other sites More sharing options...
premiso Posted January 16, 2009 Share Posted January 16, 2009 So... * 2 * * 0 /usr/bin/php -q /home/<user>/public_html/somefolder/script.php Should do every Sunday a 2am. Hopefully that's right? Yep that should do it. Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/#findComment-738700 Share on other sites More sharing options...
The Little Guy Posted January 16, 2009 Share Posted January 16, 2009 cPanel has a built in cron editor, that may make it easier to write the cron (if your not using that) Quote Link to comment https://forums.phpfreaks.com/topic/141118-solved-hit-counter-that-resets-weekly/#findComment-738762 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.