Show location on map by IP address in PHP - php

I have a database with user information (including IP Address) and I was wondering if it's possible to show the users location on a world map by getting the IP from the database in php?
Any help appreciated :)

To view the IP address of a visitor to your site, insert this code in the area where you want it to appear.
echo $_SERVER["REMOTE_ADDR"];
You can then use the API to locate your GeoLite MaxMind visitor
http://dev.maxmind.com/geoip/legacy/geolite/

It is possible to associate an IP address with a physical location, but only loosely. IP addresses are not registered to an individual user's exact location. You will be finding the location of the administrative domain of an IP address...but still on a world map that should be good enough.
Basically it works like this. You get a tool called geoip that should come packaged with a tool called geoiplookup. You then go to http://dev.maxmind.com/geoip/legacy/geolite/ to download GeoLiteCity.dat. Then you run this command.
geoiplookup -f /path/to/GeoLiteCity.dat <target IP or hostname>
For example, just now I ran
geoiplookup -f ~/Downloads/GeoLiteCity.dat stackoverflow.com
and I got this output
GeoIP City Edition, Rev 1: US, CA, California, San Francisco, 94107, 37.769699, -122.393303, 807, 415
Using this from PHP should be easy using the built in exec function from you PHP script.

Related

Open google map from my website

I have a list of addresses in database. I can show google from these addresses in my website but I want to make a link from these addresses. When user clicks on address It will open google map in a new tab.
Just done this for a client. If you take the following php generated link:
<?php echo 'http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q='.$placestring.'&aq=&sll=&sspn=&vpsrc=0&ie=UTF8&hq=&hnear='.$near.'&t=h&z=12'; ?>
$placestring in my code is simply the address, put through a htmlentities() routine to ensure it is a safe url. The $near variable can be used to avoid doubt if your addresses are all within a certain area - i.e. if all of the addresses are in London, you could use London as the $near variable. This helps google to provide a better match. If you have postcodes (in the UK) or a lat/long then this will massively help.

Restrict website to access specific country

I am wondering if it's possible to make my website only available to a specific country.
So anyone who tries to visit the website outside the specific country, will not have access.
I was thinking of getting a php IP Geo Locator script and do a redirect if they IP address is from the country I decide.
How would you guys recommend it?
Thank you.
EDIT
This doesn't have to be 100% accurate. Just need the php code that will do what I need.
The country is Romania by the way. Thanks! :)
The answer depends on what you mean by "available to a specific country".
What if an in-country computer has an IP address not on your list? That computer won't have access, but it's located in country.
What if an out-of-country computer has an IP address on your list? That computer will have address, but it's not located in country.
What if a router with an in-country IP address forwards requests from out-of-country? What if an in-country router is part of the TOR network?
What if a citizen leaves the country and wants to get access to your in-country web site from another country? The citizen will have an IP address not your list and will be denied access.
Until you define "available to a specific country" your question cannot be answered.

Is there is any way to get users location by IP address?

Is there any kind of API or third party service that provides users location (state/city) as return value by submitting IP Address ??
This form of IP lookup is called Geolocate by IP. Try Googling for this and you will find a bunch of different companies offering the service either Paid or Free.
From my experience, if you want to get an accurate lookup, you will need to pay. If you don't mind the service to be off (quite often), then go with the free.
Maxmind seems to be the leader in this domain.
You can use this website or download the database to use it the way you want
Another webiste (Free)
You'd need to us an IP to Location geolocation service. This is an example : http://www.maxmind.com/app/city
There is also a free version that doesn't give a precise location - http://software77.net/geo-ip/

Country name from an Ip address with free IP geolocation webservice

First of all thanks to all ....
I read that i can use the free IP geolocation webservice to get Country name from an Ip address. But how i get the response to my site , Actually this is what i look , In my site there is a need of displaying the country name from Ip address. Can uou please tell in detail... How can i display the country Name from that site ..
geoip_country_code_by_name can give you the country for an arbitrary IP address or hostname (not just the one from the current visitor as apache_note("GEOIP_COUNTRY_NAME") does), it uses the same MaxMind database. There is also the geoip_country_name_by_name function if you want the full country name rather than the ISO code.
http://www.maxmind.com/app/php
You need to install the php module and then use the following code to get the country name:
$country_name = apache_note("GEOIP_COUNTRY_NAME");
Have checked this functionality in Oplim? It is free for up to 500k pageviews, and you can set your code and custom condition (country, or even areas such as all the EU).
Disclosure: I am among the service developers.

Google Map with php mysql

my problem is i want to show my registered site user on to google map but dont know how to locate the user, means i dont know the latitude and longitude of every user . I am a newbie in google map so plz help
Thanks a ton
What location data do you have for your users? Cities, states, countries?
You might want to have a look at Google's Geocoding APIs.
there are two possible ways of doing this.
Ask the user to search a google map and place themselves on it. Look here for an idea on how to do this http://www.designing4u.de/2008/08/google-maps-jquery-and-xml-saving-markers-with-user-input/
Use an IP to Location database to find out the location based on their IP. Look here for how to do this http://www.ip2nation.com/ip2nation
There is no way to reliably locate a user using their IP address. However if you are developing for a mobile device it may be possible to acquire their GPS coordinates. Or you could require them to enter an address and place a point on the map from that address with geocoding.
If you are collecting the address of each registered user, you can get the latitude and longitude on the server-side through the Google Maps HTTP Geocoding Service.
You would use the following HTTP request:
http://maps.google.com/maps/geo?q=Oxford+Street,+London&output=csv&sensor=false
Simply change the q parameter with your user's address.

Categories