IPGeolocation / ip-geolocation-api-php

IP Geolocation API PHP SDK
https://ipgeolocation.io/documentation/ip-geolocation-api-php-sdk-201809051255
Apache License 2.0
32 stars 20 forks source link

Responses in Json and Curl cames differents? #5

Closed carcleo closed 1 year ago

carcleo commented 1 year ago

I have the code

private function getLocation() : array{       

    $url = "https://api.ipgeolocation.io/ipgeo?apiKey=".env("IPGEOLOCATION_KEY");

    $cURL = curl_init();
    curl_setopt($cURL, CURLOPT_URL, $url);
    curl_setopt($cURL, CURLOPT_HTTPGET, true);
    curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Accept: application/json'
    ));
    $result =  curl_exec($cURL);
    curl_close($cURL);

    return  json_decode($result,1);

}

case i put directly on the navigator in get mode

https://api.ipgeolocation.io/ipgeo?apiKey=".env("IPGEOLOCATION_KEY")

it returns correctly the IP adress, but...

by CURL it returns always a São Paulo/Brasil IP.

Why?

How i fix it?

in time:

with $.json({}) also it return corectly.

But i woud like of use Curl

carcleo commented 1 year ago

Entendi que é preciso começar a requisição do navegador do cliente e não do server