-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurl.php
68 lines (56 loc) · 1.78 KB
/
curl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
die("You cant access this page!");
include $_SERVER['DOCUMENT_ROOT'].'/includes/tables.php';
// Load .env into current file
if (file_exists(__DIR__ . '/.env')) {
$dotenv = Dotenv\Dotenv::create(__DIR__);
$dotenv->load();
$api_key = getenv('API_KEY');
}
else {
$api_key = getenv('API_KEY');
}
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
// Initialize CURL
$ch = curl_init('http://api.ipstack.com/'.$ip.'?access_key='.$api_key.'');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Store the data:
$json = curl_exec($ch);
curl_close($ch);
// Decode JSON response:
$responseArray = json_decode($json, true);
// Define some dynamic API data variables to better determine location
$country_code = $responseArray['country_code'];
$country_name = $responseArray['country_name'];
$country_flag = $responseArray['location']['country_flag'];
$public_ip = $responseArray['ip'];
// ============================>> DEBUGGER ****
// echo ('<pre>');
// print_r ($resultJSON);
// echo ('</pre>');
// return
// Build our shortcode array which we can then pass down to our template
$atts = array (
'country_name' => $country_name,
'country_code' => $country_code,
'country_flag' => $country_flag,
'public_ip' => $public_ip,
);
// Pass these data variables from API down to our get_geolocation_tables() function
$is_country_name = $atts['country_name'];
$is_country_code = $atts['country_code'];
$country_flag_url = $atts['country_flag'];
$public_ip = $atts['public_ip'];
get_geolocation_tables(
$is_country_name,
$is_country_code,
$country_flag_url,
$public_ip
);
?>