Display IP and Location Of Users

by 12 replies
14
Hi,

I need a way to display the IP and location of my users on my squeeze page. For example like this:
"You are from YOURCITY and are using the IP YOURIP. Also you're using provider YOURPROVIDER etc."

This needs to be inserted on a specific part of the page so a simple Wordpress widget out-of-the-box won't do - After all it's to get the visitors attention.

What possibilities are there?
#programming #display #location #users
  • You have to create your plugin or pm me i can develop for you if you want to make plugin yourself use this code and develop it.

    <?php
    $ip='94.219.40.96';
    print_r(geoCheckIP($ip));
    //Array ( [domain] => dslb-094-219-040-096.pools.arcor-ip.net [country] => DE - Germany [state] => Hessen [town] => Erzhausen )

    //Get an array with geoip-infodata
    function geoCheckIP($ip)
    {
    //check, if the provided ip is valid
    if(!filter_var($ip, FILTER_VALIDATE_IP))
    {
    throw new InvalidArgumentException("IP is not valid");
    }

    //contact ip-server
    $response=@file_get_contents('http://www.netip.de/search?query='.$ip);
    if (empty($response))
    {
    throw new InvalidArgumentException("Error contacting Geo-IP-Server");
    }

    //Array containing all regex-patterns necessary to extract ip-geoinfo from page
    $patterns=array();
    $patterns["domain"] = '#Domain: (.*?)&nbsp;#i';
    $patterns["country"] = '#Country: (.*?)&nbsp;#i';
    $patterns["state"] = '#State/Region: (.*?)<br#i';
    $patterns["town"] = '#City: (.*?)<br#i';

    //Array where results will be stored
    $ipInfo=array();

    //check response from ipserver for above patterns
    foreach ($patterns as $key => $pattern)
    {
    //store the result in array
    $ipInfo[$key] = preg_match($pattern,$response,$value) && !empty($value[1]) ? $value[1] : 'not found';
    }

    return $ipInfo;
    }

    ?>
    • [1] reply
    • I would be too lazy to program this all from scratch. My approach would be to use a site like whatismyipaddress.com/ip/[visitor's ip] and then extract the output of this site with regular expressions.
      • [1] reply
  • This is how you can get the IP address of a visitor in PHP:

    $ip=$_SERVER['REMOTE_ADDR'];
    $url=file_get_contents("http://whatismyipaddress.com/ip/$ip");

    The IP is then put behind the URL so it will look like, for example, "whatismyipaddress.com/ip/66.249.66.128".

    The whatismyip site will then show info about this IP address like ISP, City, Region, Country.
    You could then extract the data that is written next to these points (you could do it with regular expressions), save each in a different variable and show the text in the variables with "echo".

    I hope you have some programming knowledge?! Otherwise it will be difficult.
  • Maxmind have some free databases that do all of this.

    Loads of advertisers already do this. If you put somebody's town name in a popup, believe me, they really take notice. So don't be too lazy to implement this!
    • [2] replies
    • There was a plugin for sale on the WSO a few days ago that will show the visitors city and state in the site when they arrive.

      I'm looking for it now, can't remember the name.
    • Exactly my idea. I want to promote proxy and VPN services so this should come in really handy. However I see no easy tutorial on how to implement Maxmind on my squeezer. Sgt Kraut, do you have some suggestion on how to get this done for a non-coder? Is this something a freelancer can code for cheap?
      • [1] reply
  • [DELETED]
    • [1] reply
    • There are few API & Geo-IP Database that can be used, Just google it. There are free version of the database also available.
  • You can make simple module for parcing information from geo site.

Next Topics on Trending Feed