I'm creating a website and I'm trying to implement a feature to prevent multivoting. The way I have it implemented at the moment seems to work to an extent, but it seems user IPv6 IP addresses change every day allowing another vote on another day per user.
Here's how I'm currently logging IPs.
This is how I'm grabbing the user IP in PHP:
$user_ip = getenv('HTTP_CLIENT_IP')?:
getenv('HTTP_X_FORWARDED_FOR')?:
getenv('HTTP_X_FORWARDED')?:
getenv('HTTP_FORWARDED_FOR')?:
getenv('HTTP_FORWARDED')?:
getenv('REMOTE_ADDR');
And here is how I'm logging each vote in the database:
$check_if_vote = mysqli_query($con, "SELECT * FROM voting_log WHERE voter_ip = '".$user_ip."' AND voted_user = '".$search."'");
if(mysqli_num_rows($check_if_voted) <= 0) {
mysqli_query($con, "INSERT INTO voting_log (voter_ip, voted_user, votetype) VALUES ('".$user_ip."', '".$search."', 0);");
} else {
echo "You have already voted for this user";
}
Is there a way to track IPv4 IP's only, as these don't seem to ever change?