hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : I need a counter to do this
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

I need a counter to do this

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 01-22-2006, 02:47 AM
viper545 viper545 is offline
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.

Reply With Quote


Sponsored Links
  #2  
Old 01-22-2006, 07:33 AM
Oras Oras is offline
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

Reply With Quote
  #3  
Old 01-22-2006, 08:09 AM
Xenatino Xenatino is offline
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

Reply With Quote
Sponsored Links
  #4  
Old 01-23-2006, 12:58 AM
Unknown01 Unknown01 is offline
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

Reply With Quote
  #5  
Old 01-23-2006, 05:10 AM
mahadri mahadri is offline
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.

Reply With Quote
  #6  
Old 01-23-2006, 05:27 AM
Burhan Burhan is offline
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

Reply With Quote
  #7  
Old 01-23-2006, 12:37 PM
realwebsolution realwebsolution is offline
WHT Addict
 
Join Date: Sep 2004
Posts: 130
fyrestrtr
Your solution seems to be fine on this case

Reply With Quote
  #8  
Old 01-24-2006, 04:24 AM
viper545 viper545 is offline
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

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
A Look at Australian Minecraft Web Host Wombat Servers Web Hosting News 2013-05-15 10:33:55
US Officials Seize 70 Domains Citing Counterfeiting, Fake SSL Certificates Web Hosting News 2012-07-13 10:45:43
Nine Things All Partners Should Know about SMBs and the Cloud - WPC 2012 Web Hosting News 2012-07-11 17:55:33
Introducing cPanel Sales Certification, with David Grega of cPanel Web Hosting News 2011-10-11 23:18:48
Hacker Group LulzSec Leaks Arizona Law Enforcement Data Web Hosting News 2011-06-24 14:14:28


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?