Script needed: After x amount of hits from same IP address -> redirect

Status
Not open for further replies.

cheesecake

Regular Member
Joined
Jan 12, 2009
Messages
270
Reaction score
232
Hi guys..
I can't find a PHP script that will do this, free or commercial.



Basically I need something that will track amount of hits from an IP address and after x amounts of hits in a 24 hour period, redirect to some Y site.


This can be done with mysql (provided it doesn't fill up the DB too quick, as I'm getting 10k hits a day).

Or maybe with cookies and session tracking.

PM your prices and estimate delivery time.

Thanks.
 
PHP:
<?php
function CheckVisits($ip,$visits,$time){
	$from = (time()-$time);
	$sql = mysql_query("SELECT * FROM logs WHERE ip='".$ip."' AND time>'".$from."'");
	if (mysql_num_rows($sql)>0){
		if (mysql_num_rows($sql)>=($visits * 60 * 60)){
			return true;
		}else{
			mysql_query("INSERT INTO `logs`(`ip`,`time`) VALUES('".$ip."','".time()."')");
			return false;
	}else{
		return false;
		}
	}

if (!CheckVisits($_SERVER['REMOTE_ADDR'],'1','24')){header("location:http://google.com");exit;}
?>

With this bit:

if (!CheckVisits($_SERVER['REMOTE_ADDR'],'1','24'))

The 1 is a number, this number says user can visit the page X times before being redirected within (24) which is hours. So '1','24' means that the user can only visit your page once in 24 hours or they will be redirected to Google.

Create a DB with a table called logs and have 2 columns, ip and time.

I have not tested this yet but I am pretty sure that it should work.
 
Status
Not open for further replies.
This thread has been auto closed due to the forum's thread age policy. Read more.
Back
Top