Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.
Daily Diamond

I want to ban all of Asia

Status
Not open for further replies.
Domain Days 2024

Bender

Bending
Legacy Exclusive Member
Joined
Apr 16, 2004
Messages
1,737
Reaction score
0
well, that's possible.Not so easy, but possible.
My solution: get the IP database from webhosting.info, and when the user visits your site get the user country, then continent.If the continent is banned, send him to google or whatever.
 

prose

DNF Member
Legacy Exclusive Member
Joined
Apr 18, 2004
Messages
380
Reaction score
0
I was successful. I had to find all the asian country codes then basically check to see if that's who is visiting. Then I redirect them to google if they are from asia.

Here is a walkthrough. It skips small steps like unziping in your server, and placing the files in the same directory as your PHP conversion program.

All code was taken from various sources.


Download the IP to country database:
PHP:
http://ip-to-country.webhosting.info/downloads/ip-to-country.csv.zip

Setup the Database:
PHP:
CREATE DATABASE country;
USE DATABASE country;
CREATE TABLE iptocountry
        (ip_from int(4) unsigned,
         ip_to int(4) unsigned,
         country_code2 char(2),
         country_code3 char(3),
         country_name varchar(50));

Convert the .CSV file to MySQL.
PHP:
<?
define("SOURCE_FILENAME", "ip-to-country.csv");
define("SEPERATOR_COL", ",");
define("SEPERATOR_ROW", "\n");

mysql_connect("localhost", "user", "pass");
mysql_select_db("country");
mysql_query("DELETE FROM iptocountry") or die (mysql_error());


/*
Open file for reading
*/
$fhFile     = fopen(SOURCE_FILENAME, "r") or die ("Error opening ".SOURCE_FILENAME);
$sData      = fread($fhFile, filesize(SOURCE_FILENAME));

$aData      = explode(SEPERATOR_ROW, $sData);

foreach($aData as $sRow) {
    $aRow = explode(SEPERATOR_COL, $sRow);
    /* Prepare values for query */
    foreach($aRow as $sKey => $sValue) {
        $sValue         = str_replace("\"", "", $sValue);
        $sValue         = addslashes($sValue);
        $aRow[$sKey]    = "'".$sValue."'";
    }
    list($sIpFrom, $sIpTo, $sCountryCode2, $sCountryCode3, $sCountryName) = $aRow;
    $sQuery = "INSERT INTO iptocountry
                                (ip_from,
                                 ip_to,
                                 country_code2,
                                 country_code3,
                                 country_name)
                            VALUES
                                 (".$sIpFrom.",
                                  ".$sIpTo.",
                                  ".$sCountryCode2.",
                                  ".$sCountryCode3.",
                                  ".$sCountryName."
                            );";

    mysql_query($sQuery) or die (mysql_error());
}
?>

ADD TO TOP OF INDEX or HEADER:
PHP:
<?
$REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
$asia=array("AF","BD","BT","IO","BN","KH","CN","TP","GU","HK","IN","ID","JP","KZ","KP","KR","KG","LA","MO","MY","MV","MN","MM","NR","NP","MP","PK","PW","PH","SG","LK","TJ","TW","TH","TM","SU","UZ","VM");


    // Establishing a database connection
    $dbh=mysql_connect("localhost","user","pass");
    mysql_select_db("country");


    // Query for getting visitor countrycode
    $country_query  = "SELECT country_code2,country_name FROM iptocountry ".
         "WHERE IP_FROM<=inet_aton('$REMOTE_ADDR') ".
          "AND IP_TO>=inet_aton('$REMOTE_ADDR') ";


    // Executing above query
    $country_exec = mysql_query($country_query);


    // Fetching the record set into an array
    $ccode_array=mysql_fetch_array($country_exec);


    // getting the country code from the array
    $country_code=$ccode_array['country_code2'];

$numElements = count($asia);

for($counter=0; $counter < $numElements; $counter++)
{
        if ($country_code==$asia[$counter]) {
header("Location: http://www.google.com/");
}
}


   // Closing the database connection
   mysql_close($dbh);


?>
 

Bender

Bending
Legacy Exclusive Member
Joined
Apr 16, 2004
Messages
1,737
Reaction score
0
well, that's possible.Not so easy, but possible.
My solution: get the IP database from webhosting.info, and when the user visits your site get the user country, then continent.If the continent is banned, send him to google or whatever.
 

DavidAusman

David Ausman
Legacy Exclusive Member
Joined
May 15, 2005
Messages
682
Reaction score
0
Does the asian bring shit to you, How about banning your own ass :cheeky: ?
 
Status
Not open for further replies.

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Sedo - it.com Premiums

IT.com

Premium Members

Premium Members

MariaBuy

New Threads

Our Mods' Businesses

UrlPick.com

*the exceptional businesses of our esteemed moderators

Top Bottom