Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create a countup clock in php

Status
Not open for further replies.

martinb7

Programmer
Joined
Jan 5, 2003
Messages
235
Location
GB
hi, i was wondering, how would you make a countup clock in php. here's what i want to do:

I have a poll system and when they submit the vote i would like to start a counter (for 1 hour) so they can't vote again till an hour has passed.

Basically i want a counter that starts at 0 n when it reaches 60mins i want it to do something.

Any ideas??

Thanx

Martin

 
I will preface this by saying no solution for this problem will be deterministic because HTTP is a stateless protocol and users can legitimately share IP addresses.

You could set a cookie with a 1-hour expiration. If the cookie exists, don't allow the person to vote. The problem is, a knowledgeable user could dump his cookie store and vote whenever he wanted.

You could create a database that records voter IP addresses and voting time/date and not allow any IP address to vote more than once per hour. But with NAT, users often share IP addresses. You could be locking out legitimate voters.




Want the best answers? Ask the best questions: TANSTAAFL!!
 
"How do I duplicate this other site's unspecified functionality?" is not a PHP question. It's a web-site design question.

&quot;I want to do <something>. How do you recommend that I do this in PHP?&quot; is a PHP question.

If you want to duplicate another person's site, I recommend that you figure out what he's doing.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
I would love to see your rivals solution as this foxes many web programers, how do I remember users over time ??
 
You can't. Not deterministically for the purposes of preventing repeated user action.

The thing is that state-preservation mechanisms in HTTP (session variables, cookies) are designed to transport data for use as positive identification. The assumption is that if a user is in a site that is using cookies to maintain state (and PHP's session system uses cookies by default), then the user will want the cookie to exist to maintain his data.

Locking a user out in an attempt to transport data is a form of negative identification. You must make the assumption that the user will want to do what you are trying to prevent -- in this case, voting more than once in an hour. But there is no method of placing an identifying token on the user's machine to lock him out that the user can't remove.

Some programmers then record the IP address of the user and lock out that address. The problem with this method is that IP address spaces are getting crowded, so a lot of ISPs and other organizations are sharing a single IP address over a large number of clients. Lock out one IP address for an hour and suddenly every user on that ISP can't vote for an your because they're all sharing a single IP address.

One might try requiring users to register and locking out a particular login. Since there is no method of deterministically identifying a user on the internet, there is nothing to stop a user from creating multiple accounts and performing an action multiple times, once each as a different user.


Want the best answers? Ask the best questions: TANSTAAFL!!
 
is it possible to create a session that lasts for an hour and when an hour has passed, the session disapears??

or should i set a cookie? whats best?

thanx

Martin

Computing help and info:

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top