Log in

View Full Version : ip storing, then preventing that ip to access the same thing again



Demonicman
02-27-2007, 08:32 PM
simple question

how do you make a php code so that an ip address is stored in a mysql, then if they go back to that page a different thing comes up?

(for instance... boxer gave me a good poll script but i dont want anyone voting more than once... so i want it to add the ip to the mysql table after they have voted on one thing (there are multiple polls on one page) it says they cant vote on it anymore)

for instance examplesvote.php has 3 seperate polls on it, and once a person votes, it says they have voted... and writes on poll.txt... then when they try to vote again, it says "sorry you have already voted on this ip"

for reference go to http://www.kalrith.com/vote.php to see what im talking about

Twey
02-27-2007, 08:39 PM
This is a bad idea, since the user can use proxies to get around it. I have a friend who absolutely loves RapidShare: RapidShare uses this sort of system to ensure that an unregistered user can't download more than his/her fair share in a given timelimit, but my friend has dial-up, so he downloads, reconnects, and downloads again as many times as he likes.

Demonicman
02-27-2007, 08:43 PM
a high percent of people dont know how to use proxies

i really just want to know, besides if you have to log in, a lot of proxies dont let you log on to things without paying, so it is still a nice feature

at least tell me a way i can prevent users from voting twice... i have already got that system completed where users can register, log on, and log off, so i guess i can make it so that they would have to re-register to vote again please

Twey
02-27-2007, 08:51 PM
You're forgetting, as well, that a lot of ISPs run users' requests through a proxy or web cache first, so by stopping one person from voting you might be stopping a whole region or perhaps even a whole country from voting (as seen with the Great Firewall of China).
i have already got that system completed where users can register, log on, and log off, so i guess i can make it so that they would have to re-register to vote again pleaseThat's a much better idea. Obviously still bypassable, but it takes more effort and won't inconvenience innocent users.

pcbrainbuster
02-27-2007, 08:58 PM
LOL:) great firewall of china - good one

Demonicman
02-27-2007, 08:59 PM
ok ok its a great idea but any examples so i can put it to use? :)

Twey
02-27-2007, 09:16 PM
Well, without knowing how your login system works, I can't modify it.

boxxertrumps
02-27-2007, 09:22 PM
if you wanted the poll code modified, you should have asked...
ill get on it.
EDIT:
made changes to match yours. you'll only have to copy this new file over your old one.


<?php
$savefile = "save.txt";
$ipfile = "ip.txt";
$cho = $_POST['choice'];
$address = $_SERVER[REMOTE_ADDR];

$mes = array(
"File Not Found",
"You, or someone using the same proxy or on the same network, have already voted.",
"You picked choice number ". $cho ."\r\n<br>Click <a href=\"?look\">Here</a> to View The Results."
);
$contentsave = file_get_contents($savefile);
$file = explode("|",$contentsave);
$contentip = file_get_contents($ipfile);
$ip = explode("\r\n",$contentip);
if(!$file || !$ip) {die($mes);};
$in = array_search($address, $ip);

if(isset($cho)) {
if($ip[$in] == $address) {
echo $mes['1'];
} else {
$file[$cho]++;
$data = implode("|",$file);
/* Save Poll Choice */
$handle = fopen($savefile,"w+");
fwrite($handle,$data);
fclose($handle);
/* Write IP */
$handip = fopen($ipfile,"a+");
fwrite($handip,$address ."\r\n");
fclose($handip);
/* Echo Out Choice Num */
echo $mes['2'];
};
} elseif (isset($_GET['look'])) { ?>

#1 - Awesome: <?php echo $file['0']; ?><br>
#2 - Ok: <?php echo $file['1']; ?><br>
#3 - Terrible: <?php echo $file['2']; ?><br>

<?php } else { ?>
<form action="poll.php" method="post">

#1 - Vote that the game is Awesome: <input type="radio" name="choice" value="0"><br>
#2 - Vote that the game is Ok: <input type="radio" name="choice" value="1"><br>
#3 - Vote that the game is Terrible: <input type="radio" name="choice" value="2"><br>

<input type="submit" value="Vote" name="Vote"></form>
<?php };
?>

Demonicman
02-28-2007, 03:12 AM
wow thanks! yet again a life saver! also that was me that added you on msn

Blake
02-28-2007, 03:52 AM
I use a system like that for the guestbook on my band's website and it works great. It blocks about half of the spam that we get. The rest is blocked by other means.

Here are the relevant sections of code.

Checking if an IP is blocked:




<?php

include('../render/private/db_connect.inc');
$query = "SELECT * FROM ban WHERE ip = '" . $REMOTE_ADDR . "'";
$result = @mysql_query($query);
if ($result)
{
if (mysql_num_rows($result) != 0)
{
echo '<body>
Your IP address, ' . $REMOTE_ADDR . ', has been blocked. This is likely because we have
received a large volume of spam from your IP address. Please contact Blake if you feel
that this is a mistake.
</body></html>';

$query2 = "UPDATE ban SET blocks = blocks + 1 WHERE ip = '" . $REMOTE_ADDR . "'";
$result2 = @mysql_query($query2);
exit();
}
}

?>


Blocking or unblocking an IP



$query = NULL;
$msgid = NULL;

if ($opt == 'block')
{
$query = "INSERT INTO ban (ip) VALUES ('" . $ip . "')";
$msgid = 'ib';
}
else if ($opt == 'unblock')
{
$query = "DELETE FROM ban WHERE ip = '" . $ip . "'";
$msgid = 'iu';
}
else
{
header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF'])
. "admin.php?action=NULL&msgid=ip");
exit();
}

include('../render/private/db_connect.inc');
$result = @mysql_query($query);

Demonicman
02-28-2007, 04:38 AM
Your IP address, ' . $REMOTE_ADDR . ', has been blocked. This is likely because we have received a large volume of spam from your IP address. Please contact Blake if you feel that this is a mistake.

i would add a WAY to contact you

this happened to me on another site and there was no way i could get in contact without hacking back in :P

Blake
02-28-2007, 04:44 AM
Yes, that's definitely a good idea. :)

I have a link on the main page rather than on that page, though, because I want to leave spammers at a dead end.

Demonicman
02-28-2007, 05:12 AM
i was like... ok lets see contact the admin... ill just... uhhhhhhhh how the heck do i contact him! lol