<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
require("includes/debug.php");
require("includes/functions.php");
require("includes/logincheck.php");
require("includes/settings.php");

if (!isset($_GET['ip']) || $_GET['ip'] == "") {
    exit('Chamada Invalida');
}
$url = "http://ipinfo.io/{$_GET['ip']}/json";
//$url = "http://freegeoip.net/json/{$_GET['ip']}";
$location = json_decode(file_get_contents($url), true);
/*
  array(7) {
  ["ip"]=>
  string(14) "107.170.92.222"
  ["hostname"]=>
  string(11) "No Hostname"
  ["city"]=>
  string(8) "New York"
  ["region"]=>
  string(8) "New York"
  ["country"]=>
  string(2) "US"
  ["loc"]=>
  string(16) "40.7267,-73.9981"
  ["postal"]=>
  string(5) "10012"
  }
 */
//var_dump($location);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Localização Ip</title>
        <link rel="shortcut icon" href="favicon.ico"/>
        <link rel="apple-touch-icon" href="favicon.png"/>     
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
    </head>
    <body style="padding: 10px">
        <div style="border: solid 0px">
            <h3>IP: <?php echo $location["ip"] ?></h3>
            <p>
                <strong>Hostname:</strong> <?php echo (isset($location["hostname"]) && $location["hostname"] != "") ? $location["hostname"] : "Não cadastrado" ?>
                <br/><strong>Cidade:</strong> <?php echo (isset($location["city"]) && $location["city"] != "") ? $location["city"] : "Não cadastrado" ?>
                <br/><strong>Estado:</strong> <?php echo (isset($location["region"]) && $location["region"] != "") ? $location["region"] : "Não cadastrado" ?>
                <br/><strong>Pais:</strong> <?php echo (isset($location["country"]) && $location["country"] != "") ? $location["country"] : "Não cadastrado" ?>
                <br/><strong>Provedor:</strong> <?php echo (isset($location["org"]) && $location["org"] != "") ? $location["org"] : "Não cadastrado" ?>
            </p>
        </div>
    </body>
</html>



