Page 1 of 1

Rating System user validation

Posted: Sun Apr 27, 2003 10:28 am
by Watcher_TVI
I've picked up an image gallery script from SourceForge that is almost perfect for what I want with one exception. The rating system sporadically allows multiple votes from the same user and I'm not sure why. This is the code used to determine if an image has already been rated;

Code: Select all

<?php
function already_rated($nom)
{
  global $sDB,$nConnection,$sTableRatings;
  $cmd="select * from $sTableRatings where pic_name='".addslashes($nom)."' and ip='".getenv("REMOTE_ADDR")."'";
  $res=mysql_db_query($sDB,$cmd,$nConnection);
  $row=mysql_fetch_array($res);
  return($row);
}
?>
This is the code associated with retrieving the rating;

Code: Select all

<?phpfunction get_rating($nom)
{
  global $sDB,$nConnection,$sTableRatings;
  $cmd="select avg(rating), count(*) from $sTableRatings where pic_name='".addslashes($nom)."'";
  $res=mysql_db_query($sDB,$cmd,$nConnection);
  $row=mysql_fetch_array($res);
  return ($row[1]?$row[0]:false);
}
?>
Now in the MySQL the table for ratings has the IP number along with the image file name. What I can't figure out is why when it checks to see if the image has already been rated it does not return the IP in that table and deny another vote.

This may not be enough information and if not I would be happy to offer more, along with the URL where this is set up. Any suggestions on where to start looking to resolve this issue would be greatly appreciated.

Cheers!

Posted: Mon Apr 28, 2003 7:50 am
by oQEDo
Watcher,
Any chance you could give us some more information on this one.

ie. If the user has already voted, should it then not allow them to vote again by hiding the vote option or does it still allow them to vote, checks their IP after the vote and does not register it if the IP already appears?

The hyperlink would be helpful or the full code.

RM

Posted: Mon Apr 28, 2003 9:21 am
by Watcher_TVI
Sure can...

Basically this is going to be used for a contest. The participants upload the finished image and then all participants can rate the image. Since it is a contest the IP needs to be verified so that multiple votes cannot take place. I realize that checking the IP isn't the best method but they won't have time to reboot and grab a new one during the voting phase of the contest.

The link to upload and the link to vote are both on the main page at;
http://www.thevirtualillusion.com

Cheers!

Posted: Mon Apr 28, 2003 5:04 pm
by oQEDo
It seemed to work OK for me. The reason that it may not work sometimes is that the page may be caching.
Have a read of this and try inserting the example code to prevent caching and it may help...
http://php.weblogs.com/stories/storyReader$550

Posted: Mon Apr 28, 2003 5:26 pm
by Watcher_TVI
You may be on to something here...:)

I added the code and the initial testing seemed to indicate that may have been what was happening. We'll give it a full run tonight and I'll let you know how it goes.

Thanks!

<edit>

I wanted to let you know the caching was a big part of the problem. It seems to be working fine now and I want to thank you for your help...

</edit>

Posted: Wed Apr 30, 2003 2:54 am
by oQEDo
No probs :lol:
Did it sort out the problems?

Posted: Wed Apr 30, 2003 10:49 am
by Watcher_TVI
It did, there is also an issue with using the "next selection" link when voting. When using that there were no queries to determine if you had voted on that selection or not. It only validated if you voted from the main screen. I just removed that link, to query the database for every single selection 20 different ways is extremely sloppy and piggish. I'd kill my server on Contest night...;)

Thanks again for the help!