0

I have a system which records every member's IP address, browser and operating system.

I would like to somehow implement this.

Is there anyway in which I can post the users IP to their website, pulling values such as ISP and country, and store them in my local MySQL database for quick access when running queries on certain abusive users?

George Cummins
  • 28,485
  • 8
  • 71
  • 90
  • as ling as you know ip!=user –  Jun 25 '13 at 21:44
  • Do you think this a wise idea? As the user is more then likely using a dynamic IP address at least. Which will then render all this information useless. The geo data is from here http://www.ipligence.com/ – Liam Sorsby Jun 25 '13 at 21:32

4 Answers4

0

IP to location isn't always accurate and can easily be overcome, but this might help you

Rob W
  • 9,134
  • 1
  • 30
  • 50
0

PHP has native support for Maxmind's GeoIP services. See this PECL extension for details.

Alex Howansky
  • 50,515
  • 8
  • 78
  • 98
  • thanks the only reason im using iplocation.net is that it gets details from several other services such as Geolocation data from IP2Location (Product: DB4), Geolocation data from IPligence (Product: Max),Geolocation data from IP Address Labs (Product: Pro) and Geolocation data from GeoIP Javascript from MaxMind so ideally i would like to just post and get from this site as i can parse all these details into a database, – user2521779 Jun 25 '13 at 21:46
0

check this site out : http://ipinfodb.com/ip_location_api.php

they offer API to pass an ip address to there services to return geolocation back in either XML/JSON, which can then be parsed on your PHP script.

An example of how to use it looks like this:

<?php
include('ip2locationlite.class.php');

//Load the class
$ipLite = new ip2location_lite;
$ipLite->setKey('<your_api_key>');

//Get errors and locations
$locations = $ipLite->getCity($_SERVER['REMOTE_ADDR']);
$errors = $ipLite->getError();

//Getting the result
echo "<p>\n";
echo "<strong>First result</strong><br />\n";
if (!empty($locations) && is_array($locations)) {
  foreach ($locations as $field => $val) {
    echo $field . ' : ' . $val . "<br />\n";
  }
}
echo "</p>\n";

//Show errors
echo "<p>\n";
echo "<strong>Dump of all errors</strong><br />\n";
if (!empty($errors) && is_array($errors)) {
  foreach ($errors as $error) {
    echo var_dump($error) . "<br /><br />\n";
  }
} else {
  echo "No errors" . "<br />\n";
}
echo "</p>\n";
?>

maybe this will get you moving in the right direction?

Dave
  • 1,049
  • 10
  • 6
0

If you really want to pull data from http://www.iplocation.net/, then here is a quick dirty function. but to use this function you need to download and include PHP Simple HTML DOM Parser

Here is the code

<?php
  require_once( "path to simplehtmldom.php" );

  $ip_info  = ip_info( "223.196.190.40", 1 );
  print_r( $ip_info );
  /**
   * It will output...
    Array
    (
      [IP Address] => 223.196.190.40
      [Country] => India
      [Region] => Maharashtra
      [City] => Pune
      [ISP] => Idea Isp Subscriber Ip Pool
    )
  **/


  /**
   * ip_info()
   * @param $ip - IP address you want to fetch data from
   * @param $provider IP provider ( 1 = IP2Location, 2 = IPligence, 3 = IP Address Labs, 4 = MaxMind )
   * @return array
   */
  function ip_info( $ip = "127.0.0.1", $provider = 1 ) {
    $indx = array(
      1 =>  10,
      2 =>  11,
      3 =>  12,
      4 =>  13
    );
    $data = array();
    $url  = "http://www.iplocation.net/index.php";
    $ch   = curl_init();
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_FRESH_CONNECT, true );
    curl_setopt( $ch, CURLOPT_FORBID_REUSE, true );
    curl_setopt( $ch, CURLOPT_HEADER, false );
    curl_setopt( $ch, CURLOPT_NOBODY, false );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 2 );
    curl_setopt( $ch, CURLOPT_BINARYTRANSFER, false );
    curl_setopt( $ch, CURLOPT_REFERER, $url );
    curl_setopt( $ch, CURLOPT_URL, $url );
    curl_setopt( $ch, CURLOPT_POST, true );
    curl_setopt( $ch, CURLOPT_POSTFIELDS, "query=".urlencode( $ip )."&submit=Query" );
    $response = curl_exec( $ch );

    $html = str_get_html( $response );
    if ( $table = $html->find( "table", $indx[$provider] ) ) {
      if ( $tr1 = $table->find( "tr", 1 ) ) {
        if ( $headers = $tr1->find( "td" ) ) {
          foreach( $headers as $header ) {
            $data[trim( $header->innertext )] = null;
          }
        }
      }
      if ( $tr2 = $table->find( "tr", 3 ) ) {
        reset( $data );
        if ( $values = $tr2->find( "td" ) ) {
          foreach( $values as $value ) {
            $data[key( $data )] = trim( $value->plaintext );
            next( $data );
          }
        }
      }
    }
    unset( $html, $table, $tr1, $tr2, $headers, $values );
    return $data;
  }
?>
bystwn22
  • 1,776
  • 1
  • 10
  • 9