Web Hosting Talk







View Full Version : PHP IP Restriction...


crEA-tEch
12-10-2003, 06:26 PM
Hey guys :)

I'm making a poll system.. but I'm struggling to find out how to make it so when you've voted off your IP.. you can't vote off that IP again for 24hours... any ideas??

crE

MGCJerry
12-10-2003, 07:00 PM
Heres a quick thought... Sorry, I dont have any code to go with it though... However, you didnt say if you had access to a database, my post is going to assume you do...

Have the script check the user's IP, and compare it with a database, and if it isnt in the database, it will allow them to vote. After they vote, it enters their IP, and a timestamp into the database... If an IP has already voted, when the script searches the database, it will coompare the timestamp stored in the database to the current timestamp and do the math to find out if it has been 24 hours. If it is over 24 hours, it allows the vote and records it into the database, if it is under 24 hours, it'll return an error message, or just display the current results with no vote option......

Just a thought... Hope I made sense. :)

crEA-tEch
12-10-2003, 07:05 PM
that sounds like a good idea! (yeah i am using a database :))

but how di i make it so it calculates if its 24hours after it ws entered into the db?

crE

PHPConcepts
12-10-2003, 08:34 PM
something like this,

$date = time() - 86400;

SELECT * FROM votes WHERE vote_time < $date && ip = '$ip'

should work well for you.

added note: this is assuming you are storing the last vote time as a unix timestamp, just use time() to get the current time stamp and store it in the db.