PHP details and info about an IP - php

I want a way to get the IP details like country name. I am getting the IP address using this code :
$_SERVER['REMOTE_ADDR'];
But I don't know how to get info of that IP.

IP address ranges are assigned to top providers that usually represent countries. The ranges are subdivided and sold to sub regions. This covers 90% of the case, although some ISPs can cover multiple countries, and addresses get bought and sold all the time. A commercial database is actively maintained. You may use such database (one example would be the MaxMind GeoIP database) to perform a reverse IP lookup. i.e. (IP -> geo division). There's no deterministic/mathematical way to look at the IP and "figure out" its origin. Location is not forwarded in the IP request.

Related

notifying user you use their IP address

I'm making a satistics program in PHP but do i need to notify the user that i am storing their Ip address? I've converted it to an INT with ip2long but i am not sure if it is allowed without notification or a privacy statement on your site.
In short:
Is it allowed to Save the visitors IP without their knowing?
An IP address in isolation is not personal data under the Data Protection Act, according to the Information Commissioner. But an IP address can become personal data when combined with other information or when used to build a profile of an individual, even if that individual's name is unknown.
In the hands of an ISP an IP address becomes personal data when combined with other information that is held – which will include a customer's name and address. In the hands of a website operator, it can become personal data through user profiling.
Most sites do not profile their users using IP addresses. They typically use IP addresses for demographic purposes such as counting visitors, their countries of origin and their choice of ISP. Their organisation might also be identifiable.
Sites typically gather statistical data about the path that users take through a website and the page from which they left the site. Banking websites might also use IP addresses as a security measure – for example, if a customer regularly accesses his account from an IP address in London, access to that customer's account from an IP address in Moscow might indicate fraud.
The most common privacy concern surrounding IP addresses is their use in marketing. A visitor's path through a website could be followed and any adverts that are clicked can be identified. On the next visit, that user could be shown ads that are similar to those he clicked on the previous visit. But this fails when the user has a dynamic IP address: the user will be unknown.
Other alternative would be:
Accordingly, most websites prefer to use cookies to track users for personalised marketing purposes in preference to IP addresses. A cookie is a small text file that is sent from a website to a visitor's computer. The cookie file can be used to identify an individual and a website operator can build a detailed profile of that person's activity at its site. Users can set their web browsers to refuse cookies but most users accept them, often unwittingly.
I may be wrong but since IP is not a personal data and since you are just using it for demographic purposes, you don't have to notify the users about it. The process is pretty much legal, and almost all websites are using this for tracking purposes.
For more information
Others

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.

Show Content Only to Users in a Geo Location

I would like to show a sidebar advert to users only in a specific location (San Francisco). Would I sniff their IP, then if it fits in the San Fran IP area create an If/Else to show. If the IP != San Fran IP location then don't show?
Or do I not use IP to track their location these days?
The only realistic option is to use the user's IP address. This will not always be correct (will be wrong e.g. for proxy or VPN users), but workable. For this you need a database that maps IPs to countries (geolocation database).
There are many geolocation services available, but mostly not for free. See this answer: https://stackoverflow.com/questions/283016/know-a-good-ip-address-geolocation-service for details.
The answer is the whois database. Use the whois command on Linux, for example:
$ host www.stackoverflow.com
www.stackoverflow.com is an alias for stackoverflow.com.
stackoverflow.com has address 69.59.196.211
stackoverflow.com mail is handled by 20 alt1.aspmx.l.google.com.
stackoverflow.com mail is handled by 30 alt2.aspmx.l.google.com.
stackoverflow.com mail is handled by 40 aspmx2.googlemail.com.
stackoverflow.com mail is handled by 50 aspmx3.googlemail.com.
stackoverflow.com mail is handled by 10 aspmx.l.google.com.
$ whois 69.59.196.211
OrgName: Peak Inc.
OrgID: PEAKIN-3
Address: 1600 SW Western Suite #180
City: Corvallis
StateProv: OR
PostalCode: 97333
Country: US
...
Use the first "County" or "country" field. You will get the country of the network block which contains the IP. Try it at http://whois.domaintools.com/
Yes, you would use their IP address. You would need to download one of the following IP location databases and match the visitor's IP address to it:
http://ipinfodb.com/ip_database.php
That will give you their location.

Categories