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");

}

 

?>

Link to comment
Share on other sites

no error n code bur that prebuilt code allows same users to vote again ang again by changing ip adress which can be accomplished by disconnecting and reconnecting i want to modify that so each registered member can vote once only

Link to comment
Share on other sites

In that case store the memberid or username instead of the IP and check for that instead. Or have both so:

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

Link to comment
Share on other sites

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??

Link to comment
Share on other sites

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");
}

?>

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.