
01-22-2006, 02:47 AM
|
|
Newbie
|
|
Join Date: Jan 2006
Posts: 11
|
|
I need a counter to do this
I need a script to do this:
Basically it will put a counter on my webpage. I only allow 15 subscriptions to my service every day so every time somone completes subscription (this can be calculated by somone clicking on a webpage as the last step in registration) And when it hits 15, I need it to bring the user to another page to tell him/her to sign up tomorrow.
If this is possible it would be great, thanks.
|

01-22-2006, 07:33 AM
|
|
WHT Addict
|
|
Join Date: Jan 2005
Location: Baghdad, Iraq
Posts: 172
|
|
Sure you can do this by making a simple file and put a counter on it, and do a cron job to set the counter value to zero at the begining of each day.
Or make a table in DB (id,counter,date)
__________________
The Dream is the blueprint of success, the hope is the budget and hard working is the achievement
|

01-22-2006, 08:09 AM
|
|
Web Hosting Evangelist
|
|
Join Date: Oct 2004
Location: UK
Posts: 487
|
|
Create a MySQL table with the fields uid, counter, lastupdate. When a user has completed a subscription, update the table, incrementing the field counter by 1.
Implement a script into your subscription page that checks when the last update occured. If it was more than 24 hours ago, reset the counter and update the lastupdate field with an UNIX timestamp.
Hint: 24 hours is 86400 seconds 
|

01-23-2006, 12:58 AM
|
|
Newbie
|
|
Join Date: Dec 2005
Posts: 15
|
|
or you can do the easyest and probly most effiecent way and uses sessions. everytime somone finishes a sign up you go
$_SESSION[ 'times' ] = $_SESSION[ 'times'] + 1;
then you just keep checking to see if the session is 15 or over by (put this at the top of your page )
if( $_SESSION[ 'times' ] >= '15' ) {
CODE HERE TO REDIRECT TO OTHER PAGE
die();
}
Hope this helps. Dont forget to start the session by using session_start
-- Unknown01
|

01-23-2006, 05:10 AM
|
|
Newbie
|
|
Join Date: Jan 2006
Location: Chicago, IL
Posts: 28
|
|
Quote:
|
Originally Posted by Oras
Sure you can do this by making a simple file and put a counter on it, and do a cron job to set the counter value to zero at the begining of each day.
|
Clever! Very clever! I love the simplicity. However, I don't recommend using flat-text files because you have to deal with locking to atomically increment the number inside. Instead, you can have a cronjob set a field in a database to 0.
Quote:
|
Originally Posted by Oras
Or make a table in DB (id,counter,date)
|
This is a good solution, but requires a little extra logic for the first signup of the day. Also, the id field isn't needed, as you can use the date field as the primary key.
Quote:
|
Originally Posted by Xenatino
Implement a script into your subscription page that checks when the last update occured. If it was more than 24 hours ago, reset the counter and update the lastupdate field with an UNIX timestamp.
|
If at least one person subscribes every 24 hours, the counter would never reset.
Quote:
|
Originally Posted by Unknown01
or you can do the easyest and probly most effiecent way and uses sessions. everytime somone finishes a sign up ...
|
Aren't sessions tied to a specific visitor? In that case, every visitor would have their own counter, so this wouldn't work either.
|

01-23-2006, 05:27 AM
|
|
Community Guide
|
|
Join Date: Jul 2003
Location: Kuwait
Posts: 5,100
|
|
If you are already storing the information in the database, then you can simply do a count on the number of records for that day:
SELECT COUNT(id) FROM `entries` WHERE `entrydate` = CURDATE()
Then, if the result of that query is >15, display the 'sorry, come back tomorrow' page.
__________________
In order to understand recursion, one must first understand recursion.
If you feel like it, you can read my blog
Signal > Noise
|

01-23-2006, 12:37 PM
|
|
WHT Addict
|
|
Join Date: Sep 2004
Posts: 130
|
|
fyrestrtr
Your solution seems to be fine on this case 
|

01-24-2006, 04:24 AM
|
|
Newbie
|
|
Join Date: Jan 2006
Posts: 11
|
|
And if you knew nothing about programming how would you go about doing this? Could somone write me up a script? The registration is not stored in a mysql database, the number would have to progress +1 by clicking a button that submits the registration.
Thanks
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|