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