Jump to content

Limit per IP


livewirerules

Recommended Posts

You will have to keep track of the visits either in some kind of text file of in a mysql database.

 

but this will give you the ip address of the computer

$ip = $_SERVER['REMOTE_ADDR'];

 

then you will have to write the address to the preferred file or database

 

Ray

Link to comment
https://forums.phpfreaks.com/topic/115883-limit-per-ip/#findComment-595827
Share on other sites

on the page with the clicking

 

<?php
$ip = $_SERVER['REMOTE_ADDR'];

$sql = "SELECT * FROM `ip_log` WHERE `ip`='".$ip."'";
$res = mysql_query($sql) or die(mysql_error());

$err = false;

if(mysql_num_rows($res) == 0){
$sql2 = "INSERT INTO `ip_log` (`ip`,`clicks`) VALUES('".$ip."','1')";
$res2 = mysql_query($sql2) or die(mysql_error());
$err = false;
}else {
$row = mysql_fetch_assoc($res);

if($row['clicks'] >= 5){
	$err = true;
}else {
	$sql3 = "UPDATE `ip_log` SET `clicks`=`clicks`+1 WHERE `ip`='".$ip."'";
	$res3 = mysql_query($sql3) or die(mysql_error());
	$err = false;
}
}

if($err){
echo "You have already clicked this page 5 times!";
}else {
// whatever
}
?>

 

then i guess you can set a cron to run every 24 hours to reset em

Link to comment
https://forums.phpfreaks.com/topic/115883-limit-per-ip/#findComment-595836
Share on other sites

The simplest way is to use cookies, but it is very insecure, however if this is a low security situation it would do the job.

<?php
 if (!isset($_COOKIE['plays']))
   setcookie('plays', 0, time()+86400);
 else if ($_COOKIE['plays'] <= 5) {
   The code of the restricted page...
   $_COOKIE['plays']++;
 }
 else {
   echo "You are not allowed to play any more today, come back tomorrow.";
 }
?>

Link to comment
https://forums.phpfreaks.com/topic/115883-limit-per-ip/#findComment-595838
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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