Looking For Help!

tiger56

Junior Member
Joined
Jun 28, 2011
Messages
103
Reaction score
10
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!
 
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"]."')");
}

?>
 
this is not working in my case. Is there any other solution for this?
 
Back
Top