Jump to content

[SOLVED] how to make a rating system in which each user can vote only once


jck

Recommended Posts

this is the rate.php and i think it does using ip adress even when there is login facility

<?

require_once("conn.php");

 

//check the user ???

$q1 = "select * from dd_rating where ItemID = '$_POST[itemID]' and ip = '$_SERVER[REMOTE_ADDR]' ";

$r1 = mysql_query($q1) or die(mysql_error());

 

if(mysql_num_rows($r1) == '0')

{

 

$q2 = "insert into dd_rating set

ItemID = '$_POST[itemID]',

Rating = '$_POST[rr]',

ip = '$_SERVER[REMOTE_ADDR]' ";

mysql_query($q2) or die(mysql_error());

 

header("location:$_SERVER[HTTP_REFERER]&rate_error=n");

}

else

{

header("location:$_SERVER[HTTP_REFERER]&rate_error=y");

}

 

?>

thank u thats what i was thinking but i dont understand in that script how all ips are stored

 

 

are the ips stored??????

im an utter noob im just trying to modify with my little knowledge oh this

from what i understood in the script all the ip's are NOT stored

for example if i vote and then my friend in another comp voted then i will be able to vote again

if im wrong please explain how??

To get the visitors ip it's this bit of code: $_SERVER[REMOTE_ADDR]

 

When a user is logged in do you set cookies or a session variable at all with the userid or something like that so you can use: "or userid = '$_SESSION[userid] ";" at the end of the select statement.

I have also added "userid = '$_SESSION[userid]' ";" to store the userid in the table (you would have to add a new column for this in the db)

 

Set the itemid, userid, ip as primary on your db and use REPLACE INTO instead of INSERT INTO too.

 

<?php
require_once("conn.php");

//check the user 
$q1 = "select * from dd_rating where ItemID = '$_POST[itemID]' and ip = '$_SERVER[REMOTE_ADDR]' or userid = '$_SESSION[userid]' ";
$r1 = mysql_query($q1) or die(mysql_error());

if(mysql_num_rows($r1) == '0')
{
$q2 = "REPLACE into dd_rating set 
	ItemID = '$_POST[itemID]',
	Rating = '$_POST[rr]',
	ip = '$_SERVER[REMOTE_ADDR]' ,
	userid = '$_SESSION[userid]' ";
mysql_query($q2) or die(mysql_error());

header("location:$_SERVER[HTTP_REFERER]&rate_error=n");
}
else
{
header("location:$_SERVER[HTTP_REFERER]&rate_error=y");
}

?>

Do your users have to be registered to vote?

 

I did it by storing the User ID of the person that voted with the vote then checking the db for a match of username and item id to see if they voted before

 

but that only works if they are registered to vote :)

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.