Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Jak znaleźć lokalizację po IP
PFlorek
post
Post #1





Grupa: Zarejestrowani
Postów: 1
Pomógł: 0
Dołączył: 4.09.2019

Ostrzeżenie: (0%)
-----


Jak za pomocą php 7.4 mogę - mając tylko IP zdobyć informację o długości i szerokości geograficznej. - chodzi mi dokładnie o takie coś jak przedstawione na: [xyz] . Chodzi o dane - z lokalizacji IP.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
Tomplus
post
Post #2





Grupa: Zarejestrowani
Postów: 1 885
Pomógł: 231
Dołączył: 20.03.2005
Skąd: Będzin

Ostrzeżenie: (0%)
-----


Sam adres IP nie powie ci nic o geolokalizacji. Możesz dowiedzieć się co najwyżej, jakie firmy posiadają pule adresów i na ich podstawie zrobić geolokalizację.
Go to the top of the page
+Quote Post
Atlas
post
Post #3





Grupa: Zarejestrowani
Postów: 24
Pomógł: 0
Dołączył: 26.09.2007

Ostrzeżenie: (0%)
-----


Nie chcę reklamować innego forum ale znalazłem takie coś, może Ci się porzydać (IMG:style_emoticons/default/wink.gif)


You could download a free GeoIP database and lookup the IP address locally, or you could use a third party service and perform a remote lookup. This is the simpler option, as it requires no setup, but it does introduce additional latency.

One third party service you could use is mine, http://ipinfo.io. They provide hostname, geolocation, network owner and additional information, eg:

  1. $ curl ipinfo.io/8.8.8.8
  2. {
  3. "ip": "8.8.8.8",
  4. "hostname": "google-public-dns-a.google.com",
  5. "loc": "37.385999999999996,-122.0838",
  6. "org": "AS15169 Google Inc.",
  7. "city": "Mountain View",
  8. "region": "CA",
  9. "country": "US",
  10. "phone": 650
  11. }

Here's a PHP example:
  1.  
  2. $ip = $_SERVER['REMOTE_ADDR'];
  3. $details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
  4. echo $details->city; // -> "Mountain View"
  5.  


You can also use it client-side. Here's a simple jQuery example:

  1. $.get("https://ipinfo.io/json", function (response) {
  2. $("#ip").html("IP: " + response.ip);
  3. $("#address").html("Location: " + response.city + ", " + response.region);
  4. $("#details").html(JSON.stringify(response, null, 4));
  5. }, "jsonp");
  6. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  7. <h3>Client side IP geolocation using <a href="http://ipinfo.io">ipinfo.io</a></h3>
  8.  
  9. <hr/>
  10. <div id="ip"></div>
  11. <div id="address"></div>
  12. <hr/>Full response: <pre id="details"></pre>
Go to the top of the page
+Quote Post
trueblue
post
Post #4





Grupa: Zarejestrowani
Postów: 6 809
Pomógł: 1828
Dołączył: 11.03.2014

Ostrzeżenie: (0%)
-----


Lokalizacja po IP ma się nijak do rzeczywistości (nie tylko ten serwis). Może z dokładnością co do kraju.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.12.2025 - 23:11