i am creating a voting website in which a person can vote once. i want to make sure that person can vote in every 3 hour. technically speaking i want to save his ip address and cookie whenever person click on vote button the vote should increase by one and then person should not be able to vote for another 3 hour. i Want to run a session to save ip and cookie for 3 hours. i have multiple entries on one page. i don't know which way to go either saving it to database or some other method. i don't have advance knowledge of php so guys please help me out i am really stuck here. thanks
Asked
Active
Viewed 3,536 times
-7
-
3show us what you have tried so far. – Niranjan N Raju Oct 15 '15 at 05:21
-
http://thesmarttechies.com/projects/dudes/gallery.php – Anay Pareek Oct 15 '15 at 05:24
-
please provide code for what you have tried for the question you asked. – Niranjan N Raju Oct 15 '15 at 05:26
-
this is what i want to do this is my website created by someone else but i dont have php codes. the designing part is done by me but all the mysql and other php work is done by someone else help me plz.. – Anay Pareek Oct 15 '15 at 05:26
-
use php **$_SERVER['REMOTE_ADDR']** for get client ip – Abhishek Sharma Oct 15 '15 at 05:27
-
?php $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Not connected : ' . mysql_error()); } – Anay Pareek Oct 15 '15 at 05:27
-
yes i have used that but where to save it and how to stop ip from voting again – Anay Pareek Oct 15 '15 at 05:28
-
So many duplicates, i suggest you kill this thread or flag it yourself with another with the answer (i flagged one with 'save to db' full answer, but this post also great as more info bout retrieving ip address: http://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php) – Daniel Brose Oct 15 '15 at 05:28
-
Possible duplicate of [Save IP in database](http://stackoverflow.com/questions/2985405/save-ip-in-database) – Daniel Brose Oct 15 '15 at 05:29
-
$voteid = intval($_GET['voteid']); $ip = $_SERVER ['REMOTE_ADDR']; $result = mysql_query("SELECT * FROM table WHERE `ip`='$ip' AND `voteid`='$voteid` AND `timestamp` > NOW() - 24*3600"); if (mysql_num_rows($result)==0) { mysql_query("INSERT INTO table SET `ip`='$ip', `voteid`='$voteid', `timestamp` = NOW()"); echo "Thank you for your vote!"; } else echo "You may vote only once in 24 hours"; if (rand(1,5)<2) mysql_query("DELETE FROM table WHERE `timestamp` < NOW() - 24*3600"); – Anay Pareek Oct 15 '15 at 05:29
-
not duplicate because i want to save ip plus add a filter too so that same ip cannot vote again – Anay Pareek Oct 15 '15 at 05:30
-
@AnayPareek - then clean up your question, make it clear it has parts (use whitespace, ** around bold words and BR in tags if needed, see help for more info). NEVER post updates like code in comments, show signs of prior effort and research (links to the posts that dont fit your bill, ect): http://stackoverflow.com/help/how-to-ask. But if this is a compound question then it IS a duplicate as its parts all been solved already - we arent here to make your product, just help you with a specific problem you RESEARCHED, TRIED and FAILED at - show you know how and just need help on best approach – Daniel Brose Oct 15 '15 at 05:34
-
* is a duplicate in its current vague form, so see post above – Daniel Brose Oct 15 '15 at 05:35
2 Answers
1
You can capture ip address by
$_SERVER['REMOTE_ADDR'];
every time if an user clicks on vote
, first capture ipaddress. then run a query like select * from table where ipaddress = "current ip address" and question number = some id and time difference >= 3 hours
if ip address is present, then user has answered, else increment the votes.

Niranjan N Raju
- 12,047
- 4
- 22
- 41
0
You can save Ip ($_SERVER['REMOTE_ADDR']
) and time (date("Y:m:d h:i:s")
) in database.Once user votes,add ip and time entry in database.For next vote check whether that particular ip is in database.And if it is available then compare current date and date stored in database.If difference is more than 3 hours save that vote and update time,if not then discard that vote.

Dinesh Belkare
- 639
- 8
- 24
-
sir please tell me how to do that , if u can just provide me code to save it to database and to check for next vote that will be a great help. thanks – Anay Pareek Oct 15 '15 at 05:34
-
I have already provided you the things,what you have to save in database.And logic is also there.It is very simple to implement that logic using php & mysql. – Dinesh Belkare Oct 15 '15 at 05:42
-
thanks sir i will add ip to database just provide me how to check for next vote that ip is in database or not if not then count vote otherwise discard vote . plz plz plz – Anay Pareek Oct 15 '15 at 05:51