Bagaimana cara mendapatkan Geolokasi menggunakan PHP-cURL dari Alamat IP?







    $userIP = $_POST['ip'];



    $ch = curl_init($apiURL); 


    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 


    $apiResponse = curl_exec($ch); 




    $ipData = json_decode($apiResponse, true); 




        $continent = $ipData['continent'];

        $country_code_alpha2 = $ipData['alpha2'];

        $country_code_alpha3 = $ipData['alpha3'];

        $country_name = $ipData['name'];

        $country_code_numeric = $ipData['country_code'];

        $international_prefix = $ipData['international_prefix'];

        $currency_code = $ipData['currency_code'];

        $latitude = $ipData['geo']['latitude'];

        $longitude = $ipData['geo']['longitude'];


        echo 'Continent Name: '.$continent.'<br/>'

        echo 'Country Name: '.$country_name.'<br/>'

        echo 'Country Alpha-2 Code: '.$country_code_alpha2.'<br/>'

        echo 'Country Alpha-3 Code: '.$country_code_alpha3.'<br/>'

        echo 'Country Numeric Code: '.$country_code_numeric.'<br/>'

        echo 'Country International Call Prefix Code: '

                . $international_prefix.'<br/>'

        echo 'Currency Code: '.$currency_code.'<br/>'

        echo 'Latitude: '.$latitude.'<br/>'

        echo 'Longitude: '.$longitude



        echo 'Not a valid IP';






<!DOCTYPE html>

<html lang="en">



    <meta charset="UTF-8">

    <meta name="viewport" content=

        "width=device-width, initial-scale=1.0">

    <title>Get Location</title>




    <h1>Get Location Using IP Address</h1>


    <form method='post' enctype='multipart/form-data'>

        <label>Give IP address for check location</label>

        <input type='text' name='ip' />

        <input type='submit' value='Submit' name='submit' />

        <a href="index.php">Reset</a>






How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.