Jump to content

adding ip restriction on voting


darkfreaks

Recommended Posts

so im trying to add an ip restriction to voting where it would restrict the hot or not vote to one vote per IP. how would i go about this?

 

<?php
$v = $_GET["v"];//vote
$picid = $_GET["picid"];
require ("config.php");
$rater_ip_voting_restriction = true; //set voting restrictions
$rater_ip_vote_qty=1; //set number of times someone can vote
$rater_ip = getenv("REMOTE_ADDR"); //get IP
mysql_connect($conf['database_host'],$conf['database_login'],$conf['database_pass']);
mysql_select_db($conf['database_name']);
$rater_already_rated_msg="You have already rated this item. You were allowed ".$rater_ip_vote_qty." vote(s).";

if ($v == h) {
$sql = "SELECT * from hotornot WHERE picid='$picid'";

$result = mysql_query($sql);

$myrow = mysql_fetch_array($result);

$id = $myrow["id"];
$hot = $myrow["hot"] + 1;
$nothot = $myrow["nothot"];
$Limagename = $myrow["imagename"];
$Limagefile = $myrow["imagefile"];
if ($hot > $nothot) {$rank = "HOT!";}
else  {$rank = "NOT!";}

$sql = "UPDATE hotornot SET hot='$hot' WHERE picid='$picid'";
$result = mysql_query($sql);
showdone($rank,$Limagename,$Limagefile,$v);
}
else {

$sql = "SELECT * from hotornot WHERE picid='$picid'";

$result = mysql_query($sql);

$myrow = mysql_fetch_array($result);

$id = $myrow["id"];
$hot = $myrow["hot"];
$nothot = $myrow["nothot"] + 1;
$Limagename = $myrow["imagename"];
$Limagefile = $myrow["imagefile"];
if ($hot > $nothot) {$rank = "HOT!";}
else  {$rank = "NOT!";}

$sql = "UPDATE hotornot SET nothot='$nothot' WHERE picid='$picid'";
$result = mysql_query($sql);
showdone($rank,$Limagename,$Limagefile,$v);
}


function showdone($rank,$Limagename,$Limagefile,$v) {
print ("<html><Head></head><body><SCRIPT LANGUAGE=\"JAVASCRIPT\" TYPE=\"TEXT/JAVASCRIPT\">window.location=\"hotornot.php?rank=$rank&Lname=$Limagename&Limage=$Limagefile&Lv=$v\"");
print ("</SCRIPT></body></html>");

}
?>

Link to comment
Share on other sites

Create a table to list users who voted, with the columns being their IP and the ID of the poll they voted on. Then you can do this or whatever:

$pollID = 4; //Whatever poll it's on.
$checkIP = mysql_num_rows(mysql_query("SELECT * FROM voted WHERE ip='".$_SERVER['REMOTE_ADDR']."' AND poll = '$pollID'"));

if ($checkIP != 0) {
  print 'You have already voted on this poll!';
} else {
  //Do poll..
}

Link to comment
Share on other sites

Basically, in plain english it would go like this:

 

picture ID = 1 ... user IP address = 127.0.0.1

 

search the database for all records where picture ID = 1 and see if there are any that contain the user IP address 127.0.0.1

 

if num rows = 1, say "You have already voted"

else

Add their vote to the database.

 

 

Link to comment
Share on other sites

i used his example only now it isnt updating the votes when i click the link

 

Link:

 <a href="vote.php?picid=<?php echo $picid ?>&<?php echo $ip;?>&v=h">Hot</a>

 

vote.php:

<?php
$v = $_GET["v"];
$picid = $_GET["picid"];
require ("config.php");
$rater_ip = $_SERVER["REMOTE_ADDR"];
mysql_connect($conf['database_host'],$conf['database_login'],$conf['database_pass']);
mysql_select_db($conf['database_name']);
if ($v == h) {
$sql = "SELECT * from hotornot WHERE picid='$picid'AND ip='$rater_ip'";

$result = mysql_query($sql);

$myrow = mysql_fetch_array($result);
$id = $myrow["id"];
$checkIP = mysql_num_rows(mysql_query("SELECT * FROM hotornot WHERE ip='$rater_ip' AND picid='$picid'"));
$hot = $myrow["hot"] + 1;
$nothot = $myrow["nothot"];
$Limagename = $myrow["imagename"];
$Limagefile = $myrow["imagefile"];
if ($checkIP != 0) {echo"You have Already Voted On this Image!";}
if ($hot > $nothot) {$rank = "HOT!";}
else  {$rank = "NOT!";}
$sql = "UPDATE hotornot SET hot='$hot' WHERE picid='$picid' AND ip='$rater_ip'";
$result = mysql_query($sql);
showdone($rank,$Limagename,$Limagefile,$v);
}
else {

$sql = "SELECT * from hotornot WHERE picid='$picid' AND ip='$rater_ip'";

$result = mysql_query($sql);

$myrow = mysql_fetch_array($result);
$checkIP = mysql_num_rows(mysql_query("SELECT * FROM hotornot WHERE ip='$rater_ip' AND picid='$picid'"));
$id = $myrow["id"];
$hot = $myrow["hot"];
$nothot = $myrow["nothot"] + 1;
$Limagename = $myrow["imagename"];
$Limagefile = $myrow["imagefile"];
if ($checkIP != 0) {echo"You have Already Voted On this Image!";}
if ($hot > $nothot) {$rank = "HOT!";}
else  {$rank = "NOT!";}


$sql = "UPDATE hotornot SET nothot='$nothot' WHERE picid='$picid' AND ip='$rater_ip'";
$result = mysql_query($sql);
showdone($rank,$Limagename,$Limagefile,$v);
}


function showdone($rank,$Limagename,$Limagefile,$v) {
print ("<html><Head></head><body><SCRIPT LANGUAGE=\"JAVASCRIPT\" TYPE=\"TEXT/JAVASCRIPT\">window.location=\"hotornot.php?rank=$rank&Lname=$Limagename&Limage=$Limagefile&Lv=$v\"");
print ("</SCRIPT></body></html>");

}
?>

 

anyone see why it is not updating?

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.