|
-
Jan 2nd, 2012, 09:23 AM
#1
Thread Starter
Fanatic Member
Change Random Number Every Hour ?
Im using this code to generate a random number:
PHP Code:
<?php
srand ((double) microtime( )*1000000);
$random_number = rand(1000,5000);
echo "$random_number";
?>
The problem is, I want this to generate a new random number every hour. So basically I want it to generate a number that lasts for 1 hour, then have it generate another number, automatically.
Is this possible, any ideas on how to do this?
Thank you in advance.
-
Jan 2nd, 2012, 10:36 PM
#2
Re: Change Random Number Every Hour ?
Store your random number in a cookie that has a life span of one hour. If no cookie exists, create a new random number.
-
Jan 2nd, 2012, 10:56 PM
#3
Re: Change Random Number Every Hour ?
Is this random number specific to one client, or to the whole site/application? More details please.
-
Jan 3rd, 2012, 07:04 AM
#4
Thread Starter
Fanatic Member
Re: Change Random Number Every Hour ?
Its for the entire site. I just need to set a different number every hour.
Im now using this inside my function, its sets a cookie for one hour:
PHP Code:
srand(floor(time() / (60*60)));
$output = rand() % 10000;
What way could I implement the cookie option as described above?
-
Jan 3rd, 2012, 07:24 AM
#5
Re: Change Random Number Every Hour ?
If you use cookies, each user will see a different number. You need to store the number (and last update time) in a file or a database instead. On each page request, check if the time is greater than last update time plus one hour; if so, generate and save a new number.
-
Jan 5th, 2012, 01:06 PM
#6
Thread Starter
Fanatic Member
Re: Change Random Number Every Hour ?
You got any sample scripts of this?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|