neuromant Posted July 7, 2010 Share Posted July 7, 2010 Hey all, I am currently setting up a voting contest for a client. I am utilizing a simple PHP based voting script which basically just records a 'Thumbs Up' vote.. however my client now want users to ONLY be able to vote once on the WHOLE site.. so people were recommending i use a check for 'Session_ID' number.. I got word back from the developer and he sent me the following: // If session key exists... if (isset($_SESSION['your_key'])) { return FALSE; } However, I am a little uncertain as to what should I use for the key? Is there a way to tell it if there is an existing session ID and an existing vote to disallow all further voting on the site. forever. Any help is greatly appreciated! I am using the ThumbsUp script available from Codecanyon.net if it helps at all.. Thanks again! Link to comment https://forums.phpfreaks.com/topic/207067-some-help-with-session_id-and-cookies/ Share on other sites More sharing options...
AbraCadaver Posted July 7, 2010 Share Posted July 7, 2010 This is not a very good way to keep people from voting more than once. The session will expire at some point, or they can use a different computer, etc. But to answer your question, something like this on the vote page: session_start(); // have they voted, if so then die or do something else if (isset($_SESSION['voted'])) { die("You can't vote"); } // if not then let them vote and set session var $_SESSION['voted'] = true; Link to comment https://forums.phpfreaks.com/topic/207067-some-help-with-session_id-and-cookies/#findComment-1082735 Share on other sites More sharing options...
neuromant Posted July 8, 2010 Author Share Posted July 8, 2010 pardon my absolute ignorance.. but I have been messing around with this all day and havent gotten anywhere! Here's the full php script im trying to convert to disallow voting after user submits ONE vote.. <?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; } } ?> Where do you suggest I put the check for session ID? Link to comment https://forums.phpfreaks.com/topic/207067-some-help-with-session_id-and-cookies/#findComment-1082896 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.