Display IP and Location Of Users

12 replies
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?
#display #location #users
  • Profile picture of the author huzoorbux
    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;
    }

    ?>
    Signature

    PHP Developer and Founder PHPGang.com Tutorial blog to solve your broblems

    {{ DiscussionBoard.errors[9087570].message }}
    • Profile picture of the author Sgt Kraut
      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.
      {{ DiscussionBoard.errors[9087729].message }}
      • Profile picture of the author TheLoadUser
        That sounds interesting... could you explain how this works?
        {{ DiscussionBoard.errors[9088205].message }}
  • Profile picture of the author Sgt Kraut
    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.
    {{ DiscussionBoard.errors[9090507].message }}
  • Profile picture of the author brettb
    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!
    Signature
    ÖŽ Get a FREE dofollow backlink in the SEO niche ÖŽ




    {{ DiscussionBoard.errors[9090521].message }}
    • Profile picture of the author 6mdrux6
      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.
      {{ DiscussionBoard.errors[9090821].message }}
    • Profile picture of the author TheLoadUser
      Originally Posted by brettb View Post

      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!
      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?
      {{ DiscussionBoard.errors[9095919].message }}
      • Profile picture of the author Sgt Kraut
        Originally Posted by TheLoadUser View Post

        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?
        That's definitely something a freelancer can code for cheap. It should be done in no more than 10-15 minutes.
        {{ DiscussionBoard.errors[9098423].message }}
        • Profile picture of the author Thread7
          You can parse the html of a site that provides the info. But a much more standard way of doing this is to use an API from the provider. A little less "ghetto" anyways. And less dependent upon the provider keeping the same html format. Here is one that offers an API - IP Address Locator - Enter an IP address to find its location - Lookup Country Region City etc
          {{ DiscussionBoard.errors[9107559].message }}
          • Profile picture of the author TheLoadUser
            So I got this little script coded by someone on Fiverr. It seems to work but since I'm completely inept in php I have no idea how to edit the code to make it into a nice landing page.

            Script is attached and can be used freely by anyone who needs it. Maybe you guys could give me some very basic advice on how to work with this stuff? Maybe something like an HTML WYSIWYG editor but for php?
            {{ DiscussionBoard.errors[9107640].message }}
  • Profile picture of the author LeetHost
    [DELETED]
    {{ DiscussionBoard.errors[9109906].message }}
    • Profile picture of the author MYS
      There are few API & Geo-IP Database that can be used, Just google it. There are free version of the database also available.
      {{ DiscussionBoard.errors[9110043].message }}
  • Profile picture of the author Aleksenator
    You can make simple module for parcing information from geo site.
    {{ DiscussionBoard.errors[9125046].message }}

Trending Topics