/** * Get a uid for anonymous vs. registered voting */ function _vote_up_down_get_uid() { global $user; if ($user->uid) { $uid = $user->uid; } else if (variable_get('vote_up_down_anonymous_vote', 0)) { // Fake uid for anonymous users. // If the IP is valid turn it into a integer and add the number of the current day. // The current day is what limit anonymous voting to one vote per day and IP address. $hostname = (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; if ($long = ip2long($hostname)) { $uid = abs($long) + date('z'); } } else { $uid = NULL; } return $uid; }