1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Hire a Freelancer' started by cheesecake, Jan 3, 2010.

  1. cheesecake

    cheesecake Regular Member

    Joined:
    Jan 12, 2009
    Messages:
    270
    Likes Received:
    229
    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.
     
  2. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,879
    Likes Received:
    1,932
    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.
     
    • Thanks Thanks x 1