Created
January 18, 2017 02:08
-
-
Save 3D-I/f5494a1dba67ae847b058ca2e34fb7ac to your computer and use it in GitHub Desktop.
IPCF tests - IP lookup service: freegeoip.net and CURL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Usage: Download and unzip the file, upload it to your Board's root (i.e.: www.mydomain.com/phpBB3/) | |
* Point your browser to i.e.: www.mydomain.com/phpBB3/ipcfcurlfree.php - results will be on your screen | |
* @package - IPCF tests - IP lookup service: freegeoip.net | |
* @copyright (c) 2017 3Di (Marco T.) 17-jan-2017 | |
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 | |
*/ | |
define('IN_PHPBB', true); | |
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './'; | |
$phpEx = substr(strrchr(__FILE__, '.'), 1); | |
include($phpbb_root_path . 'common.' . $phpEx); | |
// Start session management | |
$user->session_begin(); | |
$auth->acl($user->data); | |
/* define the IP to be looked at */ | |
$user->ip = '104.111.111.121'; // United States = US | |
//$user->ip = '0.0.0.1'; // country_code = '' | |
//$user->ip = '127.0.0.1'; // country_code = '' | |
/** | |
* Returns whether cURL is available | |
* | |
* @return bool | |
*/ | |
function is_curl() | |
{ | |
return function_exists('curl_version'); | |
} | |
$is_curl = is_curl(); | |
/** | |
* http://freegeoip.net | |
* | |
* You're allowed up to 10,000 queries per hour by default. | |
* Once this limit is reached, all of your requests will result in | |
* HTTP 403, forbidden, until your quota is cleared. | |
*/ | |
if ($is_curl) | |
{ | |
echo 'cURL is TRUE!<br />'; | |
$curl_handle = curl_init(); | |
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); | |
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curl_handle, CURLOPT_URL, 'freegeoip.net/json/' . $user->ip); | |
$ip_query = curl_exec($curl_handle); | |
$http_code = curl_getinfo($curl_handle, CURLINFO_HTTP_CODE); | |
curl_close($curl_handle); | |
echo('<br />ip_query var<br />'); | |
var_dump($ip_query); | |
echo('<br /><br />http_code var<br />'); | |
var_dump($http_code); | |
if ($ip_query) | |
{ | |
/* Creating an array from string */ | |
$ip_array = json_decode($ip_query, true); | |
echo('<br /><br />ip_array var<br />'); | |
var_dump($ip_array); | |
if ( ($ip_array['country_code'] != '') && ($http_code == 200) ) | |
{ | |
echo '<br />' . $ip_array['country_code']; | |
} | |
else | |
{ | |
echo 'fail -> WO'; | |
} | |
} | |
else | |
{ | |
echo 'http_code = 0 -> WO'; | |
} | |
} | |
else | |
{ | |
echo 'cURL is not available - Test failed!<br />'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment