1

I am building my log system, for my software in php.

Data collection via: https://ipinfo.io/

As shown in the screenshot, just make a json_decode to read them.

Only problem for the privacy object that I can't show:

example working with for example the city parameter:

//Gets the IP Address from the visitor
$PublicIP = $_SERVER['REMOTE_ADDR'];
//Uses ipinfo.io to get the location of the IP Address, you can use another site but it will probably have a different implementation
$json = file_get_contents("http://ipinfo.io/$PublicIP/geo");
//Breaks down the JSON object into an array
$json = json_decode($json, true);
$city = $json['city'];
echo $city;

instead when I have to go into privacy, it doesn't give me anything back, what am I doing wrong?

$PublicIP = $_SERVER['REMOTE_ADDR'];
$json = file_get_contents("http://ipinfo.io/$PublicIP/geo");
$json = json_decode($json, true);
$vpn = $json["privacy"]["vpn"];
echo $vpn
  • 1
    If `vpn` is `false`, then you won't see anything because `false` shows up as blank when echoed. Try something like `echo ($vpn == true ? "Yes" : "No");` instead. Or use `var_dump($vpn);` – ADyson Sep 15 '21 at 22:04
  • sure @ADyson, I didn't rightly think that if the result is 0, it doesn't show anything. Please write the answer that I mark it as correct and thank you for your contribution .... need a coffe –  Sep 15 '21 at 22:07
  • Done - see below. Thanks. – ADyson Sep 15 '21 at 22:29

2 Answers2

0

If vpn is false, then you won't see anything because false shows up as blank when echoed.

Try something like echo ($vpn == true ? "Yes" : "No"); instead. Or use var_dump($vpn);

See also PHP - Get bool to echo false when false.

ADyson
  • 57,178
  • 14
  • 51
  • 63
0

There are two issues at least:

  1. Privacy data is only available if you have a token (i.e. you signed up), and that too only if you purchased the privacy data - see their pricing page and the addons page. Then you'll have to include the token in your request.
  2. You are requesting for /geo, which will only give back geographical data. Don't put that suffix in the request URL.

I suggest you carefully read https://ipinfo.io/developers and https://ipinfo.io/developers/data-types#privacy-data in particular for your use case.