WebQuartet Directory philippines


IP Catching

Just for educational purpose. You can limit number of IPs to get your offer or catch thieves on downloading. I don’t know where you will use this but this is simple but powerful.

Here’s the code:

<?php
$v_ip = "$REMOTE_ADDR";

$fd = fopen("visitorIPs.log", "r");
$value = "";
while(!feof($fd)){
	$value .= fread($fd, 4096);
}
fclose($fd);
$value=explode("|",$value);

if (count($value)<300) {

	$result = -1;
	for ($i = 0; $i <= count($value); $i++) {
		if (strcmp($value[$i], $v_ip) == 0) {
			$result = $i;
		}
	}

	if ($result == -1) {
		$file = fopen("visitorIPs.log", "a");
		fputs($file, $v_ip."|", strlen($v_ip."|"));
		fclose($file);

		echo "Congratulations, you made on one of the first 300 limit!";
	} else {
		echo "Thanks for visiting again!";
	}

} else {

echo "Sorry, the 300 limit is already used! Better luck on the next offer.";

}
 
?>

Save it as .php file.

Leave a Reply

You must be logged in to post a comment.


A Ross Dalangin's Network
Kabonfootprint