1. Generally use a database if you've got one - it's usually easier to maintain and it means you can easily back up the site by simply dumping the database contents.
2. Up to you. I've got a rating system for ssLinks (see link in sig) which works by updating the record for each link whenever a new vote is cast - it adds 1 to the number of votes and then adds what they voted to a field storing the TOTAL of all votes cast. When it displays the rating for a link it just divides the total of all votes by the number of votes to get the average
3. Yes you use printf, but not like that. Do this: printf ("%.2f", $number); Replace the 2 with the number of decimal points you want.
4. This is again up to you. There is NO WAY of properly preventing people from voting more than once without forcing them to register a username and password, and even then they can register more than one account. Online voting is inherently flawed because of this. It depends on how desperate you are to stop cheats (remember if they are determined they will always be able to get around your defences). Personally I just set a cookie as it's the easiest way, and recording an IP doesn't work seeing as most people are on dynamic IP addresses thanks to being on a modem. Again, it's your decision.
Originally posted by Skunk Personally I just set a cookie as it's the easiest way, and recording an IP doesn't work seeing as most people are on dynamic IP addresses thanks to being on a modem.
Personally, I like to do both. Perhaps my reasoning is a bit flawed, but here goes
Set only cookie:
User turns off cookie, proceeds to vote 1000 times in a row.
Set only IP:
Dynamic IPs, one vote per connection.
Even if a user turns off cookies, they can still only vote once per connection. Not much you can do about that (unless you match a wide range of IPs...). But if a user doesn't turn off cookies, they can still only vote once. Best of both worlds really.
to make the rating system even more "secure", i would recommend to add a 3rd thing: log the web address (like modem193.ca.aol.com or whatever) of all voters. if you only have a few votes per topic (like for this ssLinks script), it will be an effective way to check that all the ratings are fair and your mind will be more peaceful