Anaypareek, don’t save the ip in the session. No need to do that. Just grab the timestamp. Many ways
to do that. If you need to display the timestamp, I use it this way:
$timestamp = date( “Y-m-d H:i:s”);
Date and time formatted to be displayed. Save that in a “datetime” field in your database record for the
user’s IP. So, save timestamp, ip in a table. Then, when the user presses the vote button, before you
record the vote, query their IP address and grab the timestamp. (“last_time_voted” or something similar.)
Then do a compare of the timestamp to the current one using PHP’s date functions to see if it is too soon.
If too soon, tell the user so…
You can compare dates with days or hours differences using code something like this:
if ($last_vote_date"<=date(“Y-m-d H:i:s”, strtotime("-3 hours"))) { Display can’t vote yet notice… }
( Not tested, just an example… )
Some programmers might store the next available voting time instead of the time of voting. If you do that,
a simple compare to see if the current time is later than the stored one. This makes it easier. Now, you
could display a timer on the user’s vote page to show how long it is before they can vote again…
Hope that helps some…