Welcome Guest, Not a member yet? Register   Sign In
Ajax star rating bar
#12

[eluser]wiredesignz[/eluser]
It appears someone (who shall remain nameless, but has a Bear avatar), was able to send 1000 votes to the rating system. :lol:

I really didn’t bother to improve the security from the original script. But now I would suggest adding a limit field to the table with which to compare the submitted vote.

Modified ratings table
Code:
-- Table structure for table `ratings`

CREATE TABLE `ratings` (
  `id` varchar(11) NOT NULL,
  `total_votes` int(11) NOT NULL default '0',
  `total_value` int(11) NOT NULL default '0',
  `vote_limit`  int(11) NOT NULL default '0',    //added vote limit
  `used_ips` longtext,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;


Modify application/controllers/ratings_rpc.php
Code:
//get the current values!
if ($numbers = $this->ratings_model->findBy_id($id_sent))
{
    // kill the script if vote limit is exceeded.
    if ($vote_sent > $numbers['vote_limit']) die("Sorry, your vote appears to be invalid.");
    
    $checkIP = unserialize($numbers['used_ips']);
    $count = $numbers['total_votes']; //how many votes total
    $current_rating = $numbers['total_value']; //total number of rating
    $sum = $vote_sent + $current_rating; // add together the current vote value and the total vote value
    $tense = ($count == 1) ? "vote" : "votes"; //plural form votes/vote
}

...

//get the new values!
if ($numbers = $this->ratings_model->findBy_id($id_sent))
{
    $checkIP = unserialize($numbers['used_ips']);
    $count = $numbers['total_votes']; //how many votes total
    $current_rating = $numbers['total_value']; //total number of rating
    $tense = ($count == 1) ? "vote" : "votes"; //plural form votes/vote
    $units = $numbers['vote_limit']; //get the vote limit
}


Modify application/models/ratings_model.php
Code:
// get votes, values, ips for the current rating bar
if (!$numbers = $this->findBy_id($id))
{
    // insert the id in the DB if it doesn't exist already
    $data = array(
        'id' => $id,
        'total_votes' => $count,
        'total_value' => $current_rating,
        'vote_limit'  => $units,        //set the vote limit
        'used_ips' => '',
    );
    $this->insert($data);
}

...

function findBy_id($id)
{
    $this->db->select('total_votes, total_value, vote_limit, used_ips');
    $query = $this->db->getwhere('ratings', "id = '{$id}'");
    return $query->row_array();
}


Messages In This Thread
Ajax star rating bar - by El Forum - 02-14-2008, 12:12 AM
Ajax star rating bar - by El Forum - 02-14-2008, 12:14 AM
Ajax star rating bar - by El Forum - 02-14-2008, 12:16 AM
Ajax star rating bar - by El Forum - 02-14-2008, 12:20 AM
Ajax star rating bar - by El Forum - 02-14-2008, 12:32 AM
Ajax star rating bar - by El Forum - 02-14-2008, 12:51 AM
Ajax star rating bar - by El Forum - 02-15-2008, 12:13 AM
Ajax star rating bar - by El Forum - 02-16-2008, 07:20 AM
Ajax star rating bar - by El Forum - 02-16-2008, 07:36 AM
Ajax star rating bar - by El Forum - 02-16-2008, 11:49 AM
Ajax star rating bar - by El Forum - 02-16-2008, 03:34 PM
Ajax star rating bar - by El Forum - 02-16-2008, 06:06 PM
Ajax star rating bar - by El Forum - 02-16-2008, 07:26 PM
Ajax star rating bar - by El Forum - 02-18-2008, 12:11 AM
Ajax star rating bar - by El Forum - 02-18-2008, 03:25 AM
Ajax star rating bar - by El Forum - 02-18-2008, 02:43 PM
Ajax star rating bar - by El Forum - 02-18-2008, 03:14 PM
Ajax star rating bar - by El Forum - 02-18-2008, 08:40 PM
Ajax star rating bar - by El Forum - 02-18-2008, 08:43 PM
Ajax star rating bar - by El Forum - 02-18-2008, 08:47 PM
Ajax star rating bar - by El Forum - 02-18-2008, 08:52 PM
Ajax star rating bar - by El Forum - 02-18-2008, 08:56 PM
Ajax star rating bar - by El Forum - 02-18-2008, 09:51 PM
Ajax star rating bar - by El Forum - 02-18-2008, 10:20 PM
Ajax star rating bar - by El Forum - 02-18-2008, 10:32 PM
Ajax star rating bar - by El Forum - 02-19-2008, 12:45 AM
Ajax star rating bar - by El Forum - 02-19-2008, 02:00 AM
Ajax star rating bar - by El Forum - 02-19-2008, 06:23 PM
Ajax star rating bar - by El Forum - 02-19-2008, 09:13 PM
Ajax star rating bar - by El Forum - 03-14-2008, 06:18 PM
Ajax star rating bar - by El Forum - 03-17-2008, 01:17 PM
Ajax star rating bar - by El Forum - 03-18-2008, 07:54 PM
Ajax star rating bar - by El Forum - 03-19-2008, 07:53 PM
Ajax star rating bar - by El Forum - 03-19-2008, 08:06 PM
Ajax star rating bar - by El Forum - 06-02-2008, 04:05 PM
Ajax star rating bar - by El Forum - 06-05-2008, 10:01 PM
Ajax star rating bar - by El Forum - 06-05-2008, 10:25 PM
Ajax star rating bar - by El Forum - 06-06-2008, 06:39 AM
Ajax star rating bar - by El Forum - 06-06-2008, 12:28 PM
Ajax star rating bar - by El Forum - 06-11-2008, 06:53 PM
Ajax star rating bar - by El Forum - 06-12-2008, 01:00 PM
Ajax star rating bar - by El Forum - 06-17-2008, 07:42 AM
Ajax star rating bar - by El Forum - 06-17-2008, 11:04 AM
Ajax star rating bar - by El Forum - 06-17-2008, 10:50 PM
Ajax star rating bar - by El Forum - 06-23-2008, 11:43 AM
Ajax star rating bar - by El Forum - 08-24-2008, 07:10 AM
Ajax star rating bar - by El Forum - 10-15-2008, 12:30 AM
Ajax star rating bar - by El Forum - 02-24-2009, 04:11 AM
Ajax star rating bar - by El Forum - 06-03-2009, 10:47 PM
Ajax star rating bar - by El Forum - 06-03-2009, 10:56 PM
Ajax star rating bar - by El Forum - 06-04-2009, 04:34 AM
Ajax star rating bar - by El Forum - 06-04-2009, 05:27 AM
Ajax star rating bar - by El Forum - 08-09-2009, 01:26 PM
Ajax star rating bar - by El Forum - 10-28-2009, 03:18 AM
Ajax star rating bar - by El Forum - 07-01-2010, 03:39 PM
Ajax star rating bar - by El Forum - 07-02-2010, 01:18 AM
Ajax star rating bar - by El Forum - 07-02-2010, 02:04 AM
Ajax star rating bar - by El Forum - 07-02-2010, 05:41 AM
Ajax star rating bar - by El Forum - 07-04-2010, 12:14 AM
Ajax star rating bar - by El Forum - 03-10-2011, 01:56 PM
Ajax star rating bar - by El Forum - 06-26-2011, 08:53 PM
Ajax star rating bar - by El Forum - 08-16-2011, 09:43 AM
Ajax star rating bar - by El Forum - 02-01-2012, 10:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB