darkfreaks Posted March 31, 2010 Share Posted March 31, 2010 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>"); } ?> Quote Link to comment Share on other sites More sharing options...
priti Posted March 31, 2010 Share Posted March 31, 2010 you are asking "how would i go about this? " and then you are adding the codes as well !! Quit confusing !! Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 31, 2010 Author Share Posted March 31, 2010 how is it confusing, i just asked how i would go about adding it to the code. i started and just never really figured out how i would implement it into the code and make it fit. Quote Link to comment Share on other sites More sharing options...
oni-kun Posted March 31, 2010 Share Posted March 31, 2010 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.. } Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 31, 2010 Author Share Posted March 31, 2010 thanks uni i kind of figured i would need a table to compare it. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 31, 2010 Author Share Posted March 31, 2010 okay im abit confused just one last thing how would i do the id thing? would i use $id or $picid it would grab the id of the picture and return whether you have voted on it before or not right? Quote Link to comment Share on other sites More sharing options...
oni-kun Posted March 31, 2010 Share Posted March 31, 2010 Well it looks like you're wanting to use the $picid as you're looking at the ID of the picture (thus the poll on it) and seeing if they've posted on it or not. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 31, 2010 Author Share Posted March 31, 2010 so basically i would compare the $rater_ip against the database IP see if they match or not. and select the database ip and the picture id? also how would i modify the updates with the IP? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 31, 2010 Author Share Posted March 31, 2010 i have run into a delimma i cant do the last line of code $checkip my code is setup differently where it grabs the SQL result and returns it as $myrow['variable'] Quote Link to comment Share on other sites More sharing options...
Jax2 Posted March 31, 2010 Share Posted March 31, 2010 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. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 31, 2010 Author Share Posted March 31, 2010 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? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted March 31, 2010 Author Share Posted March 31, 2010 closing thread my client is being extremely rude unprofesional about me posting on here. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.