neuromant Posted July 8, 2010 Share Posted July 8, 2010 Hey all, I am still trying to figure out the correct syntax in order to make visitors only vote ONCE on the whole site. So i need some sort of check that disallows voting if the user has already voted once.. even if it was for a different submission. The idea is they can only cast ONE vote total. Here's the main script i'm assuming I have to edit.. but I am all thumbs when it comes to creating new PHP code.. <?php require_once '../../../wp-config.php'; global $wpdb; $post_ID = $_POST['id']; $ip = $_SERVER['REMOTE_ADDR']; $like = get_post_meta($post_ID, '_liked', true); if($post_ID != '') { $voteStatusByIp = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."ilikethis_votes WHERE post_id = '$post_ID' AND ip = '$ip'"); if (!isset($_COOKIE['liked-'.$post_ID]) && $voteStatusByIp == 0) { $likeNew = $like + 1; update_post_meta($post_ID, '_liked', $likeNew); setcookie('liked-'.$post_ID, time(), time()+3600*24*365, '/'); $wpdb->query("INSERT INTO ".$wpdb->prefix."ilikethis_votes VALUES ('', NOW(), '$post_ID', '$ip')"); echo $likeNew; } else { echo $like; } } ?> ANY help is very appreciated! Link to comment https://forums.phpfreaks.com/topic/207145-cookies-and-session-id-anyone/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.