Skip to content

Quick way to get all possible information from an IP address | PHP Library

License

Notifications You must be signed in to change notification settings

emreyvz/get-information-from-ip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

A PHP Library for getting all possible information from an IP Address

This PHP library provides to get all possible information from an IP address. For example it can retrieve user's country, lat-long values, country code, zip code, ISP etc.

This library written by Emre Yavuz | github.com/emreyvz

Accessible Properties

  • currentCountry
  • currentCountryCode
  • currentPlateNumber
  • currentRegionName
  • currentCity
  • currentZip
  • currentLat
  • currentLon
  • timezone
  • isp
  • org
  • as
  • ip

Accessible Methods

  • getISPLogo(@param)
  • clearTrCharacter(@param)
  • requestWithNoHeader(@param)

Examples


Get user's city by IP address

$getInformationFromIP = new getInformationFromIP();
$getInformationFromIP->ip="198.51.100.0";
$getInformationFromIP->fetchData();
echo "City: " .$getInformationFromIP->getCurrentCity();

Print ISP name And Logo

Some ISPs and logos may not avaible. Add 'AS Code' and ISP Logo URL to getISPLogo() method for proper return

$getInformationFromIP = new getInformationFromIP();
$getInformationFromIP->ip="198.51.100.0";
$getInformationFromIP->fetchData();
echo "ISP: " .$getInformationFromIP->getIsp();
echo "<img src='". $getInformationFromIP->getISPLogo() ."'>";

Block users to access a specific page by country code

$bannedCountries = ["AU","AZ","ES"];
$getInformationFromIP = new getInformationFromIP();
$getInformationFromIP->ip="198.51.100.0";
$getInformationFromIP->fetchData();
if (in_array($getInformationFromIP->getCurrentCountryCode(), $bannedCountries))
{
  header("Location: yourCountryBannedFromThisPage.html");
}

... or vice versa: Accept users to a specific page by country code

$acceptedCountries = ["AU","AZ","ES"];
$getInformationFromIP = new getInformationFromIP();
$getInformationFromIP->ip="198.51.100.0";
$getInformationFromIP->fetchData();
if (!in_array($getInformationFromIP->getCurrentCountryCode(), $acceptedCountries))
{
  header("Location: yourCountryBlockedFromThisPage.html");
}

License

About

Quick way to get all possible information from an IP address | PHP Library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages