· 6 years ago · Sep 19, 2019, 06:54 PM
1<!DOCTYPE html>
2<html lang="en">
3<head>
4<title>IP Address Lookup</title>
5<meta charset="utf-8">
6<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7<meta name="description" content="IP Lookup">
8<meta name="keywords" content="ip lookup, what is my ip, my ip address, my ip, ip address lookup, ip geolocation, latitude longitude finder, ip lookup php script, моето айпи, моят айпи адрес, моето ip, покажи айпи"/>
9<meta name="author" content="ETI's Free Stuff - www.eti.pw">
10<meta name="robots" content="all"/>
11</head>
12<body>
13
14<h2>Lookup IP Address Location</h2>
15
16<br>
17
18<?php
19$IP = $_SERVER['REMOTE_ADDR'];
20$ip = htmlentities($_GET["ip"]);
21$hostname = gethostbyaddr($_GET['ip']);
22// old API without login from: http://freegeoip.net
23// https://github.com/apilayer/freegeoip
24// $location = json_decode(file_get_contents('http://freegeoip.net/json/'.$ip));
25// with new API with login from: http://ipstack.com (www.freegeoip.net) | LogIn there to get your own access key... It's free
26// the limit is: 10000 requests on month...
27$location = json_decode(file_get_contents('http://api.ipstack.com/'.$ip.'?access_key=yourkeyhere&format=1')); // access_key!!!
28$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json")); //we use free api from: ipinfo.io too... no need key
29if(isset($_GET['ip']))
30{
31echo '<form method="get" action="">
32<input type="text" name="ip" id="ip" maxlength="15" placeholder="IP" title="Enter IP Address here" />
33<input type="submit" class="button" value="Lookup IP Address" />
34</form>';
35echo "<br><b>General IP Information</b>";
36echo "<br><b>IP: </b>" .$location->ip;
37echo "<br><b>IP type: </b>" .$location->type;
38echo "<br><b>Continent code: </b>" .$location->continent_code;
39echo "<br><b>Continent name: </b>" .$location->continent_name;
40echo "<br><b>Country code: </b>" .$location->country_code;
41echo "<br><b>Country name: </b>" .$location->country_name;
42echo "<br><b>City: </b>" .$location->city;
43echo "<br><b>State/Region: </b>" .$location->region_name;
44echo "<br><b>Region code: </b>" .$location->region_code;
45echo "<br><b>Zip code: </b>" .$location->zip; // it was zip_code before :)
46echo "<br><b>Calling code: </b>" .$location->calling_code;
47echo "<br><b>Latitude: </b>" .$location->latitude;
48echo "<br><b>Longitude: </b>" .$location->longitude;
49// no more free of these 2 ... the extensions are paid
50// echo "<br><b>Time zone: </b>" .$location->time_zone;
51// echo "<br><b>Metro code: </b>" .$location->metro_code;
52echo "<br><b>Organization: </b>" .$details->org;
53echo "<br><b>Host: </b>" .$hostname;
54echo "<br><b>Your Browser User-Agent String: </b>" .$_SERVER['HTTP_USER_AGENT']; // remove this line if no need to show user-agent :)
55//echo $_SERVER['HTTP_USER_AGENT'];
56echo "<br><br>Short View:<br>";
57echo "<b>IP: </b>" .$details->ip;
58echo "<br><b>Country code: </b>" .$details->country;
59echo "<br><b>City: </b>" .$details->city;
60echo "<br><b>Region: </b>" .$details->region;
61echo "<br><b>Postal: </b>" .$details->postal;
62echo "<br><b>Hostname: </b>" .$details->hostname;
63echo "<br><b>Organization: </b>" .$details->org;
64echo "<br><b>Location: </b>" .$details->loc;
65echo <<<HTML
66<br><br><b>Geolocation Map:</b><br>
67<form action="" method="post">
68<input type="text" name="address" value="$location->city" />
69<input type="submit" class="button" value="Show City on the Map" />
70</form>
71HTML;
72echo <<<HTML
73<br><b>Map Latitude Longitude finder:</b>
74<form action="" method="post">
75Enter a latitude/longitude:
76<input type="text" name="address" value="$location->latitude $location->longitude" />
77<input type="submit" class="button" value="Go to this Location" /><br>
78<small>(You can put any latitude/longitude to see the location on the map)</small><br>
79<small>e.g. 27.3717 -81.4306</small>
80</form>
81HTML;
82}
83else {
84print ('<form method="get" action="">
85<input type="text" name="ip" id="ip" maxlength="15" placeholder="IP" title="Enter IP Address here" value="'.$IP.'" />
86<input type="submit" class="button" value="Lookup IP Address" />
87</form>');
88echo "<br>Here's what you will find out:<br><br>
89<li>Your IP (but you can check other IP)</li>
90<li>IP type</li>
91<li>Continent code</li>
92<li>Continent name</li>
93<li>Country code</li>
94<li>Country name</li>
95<li>City</li>
96<li>State/Region</li>
97<li>Region code</li>
98<li>Zip code</li>
99<li>Calling code</li>
100<li>Latitude</li>
101<li>Longitude</li>
102<li>Organization</li>
103<li>Hostname</li>
104<li>Your Browser User-Agent</li>
105<li>Map</li>
106<li>Map Latitude Longitude finder</li>
107";
108}
109?>
110
111 <style>
112 #gmap_canvas{
113 width:100%;
114 height:30em;
115 }
116
117 #map-label,
118 #address-examples{
119 margin:1em 0;
120 }
121 </style>
122
123<?php
124function geocode($address){
125 // url encode the address
126 $address = urlencode($address);
127
128 // google map geocode free api url ... keyless old api
129 // $url = "http://maps.google.com/maps/api/geocode/json?address={$address}"; // no need &key parameter :)
130// Keyless access to Google Maps Platform is deprecated since June 11th,2018 ... Get KEY: cloud.google.com/maps-platform/maps
131$url = "http://maps.google.com/maps/api/geocode/json?address={$address}&key=YOUR_API_KEY"; // key parameter contains your application's API key
132 // get the json response
133 $resp_json = file_get_contents($url);
134
135 // decode the json
136 $resp = json_decode($resp_json, true);
137 // response status will be 'OK', if able to geocode given address
138 if($resp['status']=='OK'){
139 // get the important data
140 $lati = $resp['results'][0]['geometry']['location']['lat'];
141 $longi = $resp['results'][0]['geometry']['location']['lng'];
142 $formatted_address = $resp['results'][0]['formatted_address'];
143
144 // verify if data is complete
145 if($lati && $longi && $formatted_address){
146
147 // put the data in the array
148 $data_arr = array();
149
150 array_push(
151 $data_arr,
152 $lati,
153 $longi,
154 $formatted_address
155 );
156
157 return $data_arr;
158
159 }else{
160 return false;
161 }
162
163 }else{
164 return false;
165 }
166}
167?>
168
169<?php
170if($_POST){
171 // get latitude, longitude and formatted address
172 $data_arr = geocode($_POST['address']);
173 // if able to geocode the address
174 if($data_arr){
175
176 $latitude = $data_arr[0];
177 $longitude = $data_arr[1];
178 $formatted_address = $data_arr[2];
179
180?>
181
182 <div id="gmap_canvas">Loading map...</div>
183
184 <script type="text/javascript" src="http://maps.google.com/maps/api/js"></script>
185 <script type="text/javascript">
186 function init_map() {
187 var myOptions = {
188 zoom: 14,
189 center: new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>),
190 mapTypeId: google.maps.MapTypeId.ROADMAP
191 };
192 map = new google.maps.Map(document.getElementById("gmap_canvas"), myOptions);
193 marker = new google.maps.Marker({
194 map: map,
195 position: new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>)
196 });
197 infowindow = new google.maps.InfoWindow({
198 content: "<?php echo $formatted_address; ?>"
199 });
200 google.maps.event.addListener(marker, "click", function () {
201 infowindow.open(map, marker);
202 });
203 infowindow.open(map, marker);
204 }
205 google.maps.event.addDomListener(window, 'load', init_map);
206 </script>
207
208 <?php
209 }else{
210 echo "<br>ERROR: No map found!";
211 }
212}
213?>