Jump to content

Cookies and Session ID - ANYONE????


neuromant

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.