Working on a project here at jhoom.xyz and have stuck at a place where I would like to limit voting per IP.
` function voteReview(reviewId, voteType) {
const data = {
action: 'ipf_vote_review',
reviewId: reviewId,
voteType: voteType,
postId: <?php echo $post->ID; ?>
};
jQuery.post('<?php echo admin_url('admin-ajax.php'); ?>', data, function(response) {
if (response.success) {
const reviewElement = jQuery('.single-review').eq(reviewId);
if (voteType === 'up') {
let upCount = parseInt(reviewElement.find('.thumb:first').text().match(/\d+/)[0]) + 1;
reviewElement.find('.thumb:first').html('👍 (' + upCount + ')');
} else {
let downCount = parseInt(reviewElement.find('.thumb:last').text().match(/\d+/)[0]) + 1;
reviewElement.find('.thumb:last').html('👎 (' + downCount + ')');
}
} else {
alert(response.data);
}
});
}
`
Top comments (1)
Hi Hasi,
About your question, seems to be validated in the backend, because the backend has the IP address in the PHP request when you send the vote using jQuery POST. To access to IP address you must use
$_SERVER['REMOTE_ADDR'];
to retrieve the remote address, but it may more complex than this variable (proxys and others), so you may use this answer from stackoverflow to retrieve the IP address.