Hello, First one to give the correct advice will get the $5 via paypal my website allows you to signup some countries I use the api: http://www.hostip.info/ but this service was discontinued, I need to modify this code below to work with this site: http://freegeoip.net https://github.com/fiorix/freegeoip/blob/master/README.rst if ($PREFS->conf['allow_registration'] != 1) { $TEMPLATE->set_message("info", ($LANG['register']['no_registration']), 0, 1); return 0; } $ipaddress = $SESSION->get_ip(); if ( !isset($_SESSION['ipcountry']) ) { if ( $ipaddress != '127.0.0.1' ) { $_SESSION['ipcountry'] = send_remote_request('http://api.hostip.info', '/get_html.php?ip='.$ipaddress); } else { $_SESSION['ipcountry'] = '--'; } } if ( strpos($_SESSION['ipcountry'], '(CA)') === false && strpos($_SESSION['ipcountry'], '(GB)') === false && strpos($_SESSION['ipcountry'], '(AU)') === false && strpos($_SESSION['ipcountry'], '(NZ)') === false && strpos($_SESSION['ipcountry'], '(US)') === false ) { $TEMPLATE->set_message("error", "We can accept registrations only from these countries: United States, UK, Canada, Australia, New Zealand", 0, 1); return 0; } PHP:
I tested, It does not work. the two API's show the same result differently. http://api.hostip.info/get_html.php?ip=66.249.64.0 http://freegeoip.net/json/66.249.64.0 I think you need a little more customization
<?php if ($PREFS->conf['allow_registration'] != 1) { $TEMPLATE->set_message("info", ($LANG['register']['no_registration']), 0, 1); return 0; } $ipaddress = $SESSION->get_ip(); if (!isset($_SESSION['ipcountry'])) { if ($ipaddress != '127.0.0.1') { // $_SESSION['ipcountry'] = send_remote_request('http://api.hostip.info', '/get_html.php?ip=' . $ipaddress); $temp = json_decode(file_get_contents('http://freegeoip.net/json' . $ipaddress)); $_SESSION['ipcountry'] = $temp->country_code; } else { $_SESSION['ipcountry'] = '--'; } } if (strpos($_SESSION['ipcountry'], '(CA)') === false && strpos($_SESSION['ipcountry'], '(GB)') === false && strpos($_SESSION['ipcountry'], '(AU)') === false && strpos($_SESSION['ipcountry'], '(NZ)') === false && strpos($_SESSION['ipcountry'], '(US)') === false) { $TEMPLATE->set_message("error", "We can accept registrations only from these countries: United States, UK, Canada, Australia, New Zealand", 0, 1); return 0; } PHP:
<?php if ($PREFS->conf['allow_registration'] != 1) { $TEMPLATE->set_message("info", ($LANG['register']['no_registration']), 0, 1); return 0; } $ipaddress = $SESSION->get_ip(); if (!isset($_SESSION['ipcountry'])) { if ($ipaddress != '127.0.0.1') { // $_SESSION['ipcountry'] = send_remote_request('http://api.hostip.info', '/get_html.php?ip=' . $ipaddress); $temp = json_decode(file_get_contents('http://freegeoip.net/json/' . $ipaddress)); $_SESSION['ipcountry'] = $temp->country_code; } else { $_SESSION['ipcountry'] = '--'; } } if (strpos($_SESSION['ipcountry'], '(CA)') === false && strpos($_SESSION['ipcountry'], '(GB)') === false && strpos($_SESSION['ipcountry'], '(AU)') === false && strpos($_SESSION['ipcountry'], '(NZ)') === false && strpos($_SESSION['ipcountry'], '(US)') === false) { $TEMPLATE->set_message("error", "We can accept registrations only from these countries: United States, UK, Canada, Australia, New Zealand", 0, 1); return 0; } PHP:
Try this instead if ($PREFS->conf['allow_registration'] != 1) { $TEMPLATE->set_message("info", ($LANG['register']['no_registration']), 0, 1); return 0; } $ipaddress = $SESSION->get_ip(); if (!isset($_SESSION['ipcountry'])) { if ($ipaddress != '127.0.0.1') { // $_SESSION['ipcountry'] = send_remote_request('http://api.hostip.info', '/get_html.php?ip=' . $ipaddress); $temp = json_decode(file_get_contents('http://freegeoip.net/json/' . $ipaddress)); $_SESSION['ipcountry'] = $temp->country_code; } else { $_SESSION['ipcountry'] = '--'; } } if (strpos($_SESSION['ipcountry'], 'CA') === false && strpos($_SESSION['ipcountry'], 'GB') === false && strpos($_SESSION['ipcountry'], 'AU') === false && strpos($_SESSION['ipcountry'], 'NZ') === false && strpos($_SESSION['ipcountry'], 'US') === false) { $TEMPLATE->set_message("error", "We can accept registrations only from these countries: United States, UK, Canada, Australia, New Zealand", 0, 1); return 0; } PHP:
Please try this: if ($PREFS->conf['allow_registration'] != 1) { $TEMPLATE->set_message("info", ($LANG['register']['no_registration']), 0, 1); return 0; } $ipaddress = $SESSION->get_ip(); if ( !isset($_SESSION['ipcountry']) ) { if ( $ipaddress != '127.0.0.1' ) { $json = json_decode(str_replace('\"','"',@file_get_contents('http://freegeoip.net/json/'.$ipaddress)),true); $_SESSION['ipcountry'] = $json['country_code']; } else { $_SESSION['ipcountry'] = '--'; } } if (!in_array($SESSION['ipcountry'],array('CA','GB','AU','NZ','US'))) { $TEMPLATE->set_message("error", "We can accept registrations only from these countries: United States, UK, Canada, Australia, New Zealand", 0, 1); return 0; } PHP:
Here is variant 2 using GeoIP XML output and simple xml: if ($PREFS->conf['allow_registration'] != 1) { $TEMPLATE->set_message("info", ($LANG['register']['no_registration']), 0, 1); return 0; } $ipaddress = $SESSION->get_ip(); if ( !isset($_SESSION['ipcountry']) ) { if ( $ipaddress != '127.0.0.1' ) { $xml = @simplexml_load_file('http://freegeoip.net/xml/'.$ipaddress); $_SESSION['ipcountry'] = $xml->CountryCode; } else { $_SESSION['ipcountry'] = '--'; } } if (!in_array($SESSION['ipcountry'],array('CA','GB','AU','NZ','US'))) { $TEMPLATE->set_message("error", "We can accept registrations only from these countries: United States, UK, Canada, Australia, New Zealand", 0, 1); return 0; } PHP: seems better for me