GithubHelp home page GithubHelp logo

emreyvz / get-information-from-ip Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 2.0 20 KB

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

License: Apache License 2.0

PHP 100.00%
ip-location ip-lookup ip-geolocation ip-address-lookup ip-address-geolocation

get-information-from-ip's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.