Looking For Help!

Discussion in 'Affiliate Programs' started by tiger56, Sep 1, 2012.

  1. tiger56

    tiger56 Registered Member

    Joined:
    Jun 28, 2011
    Messages:
    97
    Likes Received:
    9
    Hi Friends! I am looking for help. I am using phpbb3. Recently I add a banner to my website. The offer is not available for China. I am wanted to block this banner to the whole IP range of china not to show this offer.

    The code is between this:
    Code:
    <!-- Banner --> <!-- ENDIF -->
    What to add to make it possible. If any one know than please go a head to reply this thread.

    Thanks!
     
  2. plopster

    plopster Newbie

    Joined:
    Feb 13, 2012
    Messages:
    16
    Likes Received:
    3
    Insert the following code where your banner goes. You will need to have a sql connection open but chances are there will be if its phpbb.

    Code:
    <?php
    
    /**
     * author Webarto
     * copyright 2010
     */
    
    //create table if it doesn't exist, you can remove this later
    mysql_query('CREATE TABLE IF NOT EXISTS ip (
      id int(11) NOT NULL auto_increment,
      ip varchar(15) NOT NULL,
      `code` varchar(2) NOT NULL,
      PRIMARY KEY  (id),
      KEY ip (ip)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;');
    
    $bans = array("CN"); //array of banned country codes, 2 letters eg US
    $sql = mysql_query("SELECT * FROM ip WHERE ip = '".$_SERVER["REMOTE_ADDR"]."' LIMIT 1");
    if (mysql_num_rows($sql) > 0) { //ip found in database
      $row = mysql_fetch_assoc($sql);
      if (in_array($row["code"], $bans)) { //check if country code is in ban array
         echo "Chinese user detected."; //or do whatever you want
      }
    } else { //ip not found in database, find out where IP is from
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, base64_decode("aHR0cDovL3d3dy5nZW9wbHVnaW4ubmV0L3BocC5ncD9pcD0=").$_SERVER["REMOTE_ADDR"]);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      $data = curl_exec($ch);
      curl_close($ch);
      $data = unserialize($data);
      mysql_query("INSERT INTO ip(ip,code) VALUES('".$_SERVER["REMOTE_ADDR"]."','".$data["geoplugin_countryCode"]."')");
    }
    
    ?>
    
     
  3. tiger56

    tiger56 Registered Member

    Joined:
    Jun 28, 2011
    Messages:
    97
    Likes Received:
    9
    this is not working in my case. Is there any other solution for this?
     
  4. tiger56

    tiger56 Registered Member

    Joined:
    Jun 28, 2011
    Messages:
    97
    Likes Received:
    9
    bump ..............
     
  5. ofuture

    ofuture Jr. VIP Jr. VIP Premium Member

    Joined:
    Jul 25, 2011
    Messages:
    3,288
    Likes Received:
    317
    Gender:
    Male
    Occupation:
    Fulfill clients demand!
    Location:
    Clients Heart!
    Home Page: