Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Determining if server time was midnight?
Old 06-21-2010, 10:20 PM Determining if server time was midnight?
Skilled Talker

Posts: 83
Trades: 0
I've got a variable that will increment upon a user's action. Example: They click a link, and it adds 1 to the variable. The variable is then shown to the screen. I want this variable to be reset to 0 for the user, anytime the server's time has hit Midnight.

Could you provide a simple example script that does something like this so I can examine it and learn how it works please?
Smudly is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-22-2010, 01:19 AM Re: Determining if server time was midnight?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
One way is to keep track of the day the link was last clicked. If the current day is different from the day it was last clicked then reset the counter:
PHP Code:
$lastClicked//the day (ie date('j') ) the link was last clicked
$clickCounter;

if(
$lastClicked == date('j'))
     
$clickCounter++;
else 
{
     
$clickCounter 0;
     
$lastClicked date('j');

__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 06-22-2010, 03:55 AM Re: Determining if server time was midnight?
Phunk Rabbit's Avatar
Ultra Talker

Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
Trades: 0
Quote:
Originally Posted by NullPointer View Post
One way is to keep track of the day the link was last clicked. If the current day is different from the day it was last clicked then reset the counter:
PHP Code:
$lastClicked//the day (ie date('j') ) the link was last clicked
$clickCounter;

if(
$lastClicked == date('j'))
     
$clickCounter++;
else 
{
     
$clickCounter 0;
     
$lastClicked date('j');

If he is going to be displaying information based on this incrimental number then would a cronjob be useful? otherwise the number will remain the same until the user interacts with the site.

Have the cronjob reset the scores at midnight everynight.
__________________

Please login or register to view this content. Registration is FREE

Learn professional skills from professional people, from $6.50 a month.
Phunk Rabbit is offline
Reply With Quote
View Public Profile Visit Phunk Rabbit's homepage!
 
Old 06-22-2010, 08:02 AM Re: Determining if server time was midnight?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
A "cron hob" would only work if all the scores are held in a database, it could not affect "scores" held in cookies or sessions.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Determining if server time was midnight?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.26060 seconds with 12 queries