Skip to content

Instantly share code, notes, and snippets.

View dawidbeno's full-sized avatar
🏠
Working from home

Dávid Beňo dawidbeno

🏠
Working from home
View GitHub Profile
@dawidbeno
dawidbeno / get_location.php
Created April 29, 2025 09:35
Get location based on IP address
<?php
// Get the client's IP address
$ip = $_SERVER['REMOTE_ADDR'];
echo "Request IP: " . $ip . "<br><br>";
echo "<h3>Method 1: Using cURL</h3>";
// Method 1: Using cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "http://ipinfo.io/" . $ip . "/json");