Skip to content

Commit 473d293

Browse files
author
TrinsyCa
committed
first commit
1 parent d7074ce commit 473d293

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

index.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
// Get the user's IP address
3+
$ip = $_SERVER['REMOTE_ADDR'];
4+
// Get location information using the IP address
5+
$url = "http://ip-api.com/json/{$ip}";
6+
$ch = curl_init($url);
7+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
8+
$response = curl_exec($ch);
9+
curl_close($ch);
10+
11+
// Convert the JSON response to a PHP array
12+
$data = json_decode($response, true);
13+
14+
if ($data && $data['status'] === 'success') {
15+
echo "IP Address: " . $data['query'] . "<br>";
16+
echo "Country: " . $data['country'] . "<br>";
17+
echo "Country Code: " . $data['countryCode'] . "<br>";
18+
echo "Region: " . $data['regionName'] . "<br>";
19+
echo "Region Code: " . $data['region'] . "<br>";
20+
echo "City: " . $data['city'] . "<br>";
21+
echo "ZIP Code: " . $data['zip'] . "<br>";
22+
echo "Latitude: " . $data['lat'] . "<br>";
23+
echo "Longitude: " . $data['lon'] . "<br>";
24+
echo "Timezone: " . $data['timezone'] . "<br>";
25+
echo "ISP: " . $data['isp'] . "<br>";
26+
echo "Organization: " . $data['org'] . "<br>";
27+
echo "AS: " . $data['as'] . "<br>";
28+
} else {
29+
echo "Unable to retrieve location information.";
30+
}

0 commit comments

Comments
 (0)