Search:
Main Menu
Login | RSS |

Quick PHP Code Tips and Examples

PHP Programming Tips, Tutorials and Source Code Examples for newbie

Detect ip location, operating system and browser using PHP Detector Library

May 15th, 2007 by Jon Moffet

I've decided to share my PHP Detector library to the public which I've coded somewhere around 2006. The library does wonders in detecting IP address geo-location, operating system and the type of browser used based on its user-agent information.

The ip address->geo-location information is provided for free from ShowIP fakap webservice.

The library is handy for for creating web application which serve content depending on users location and type of operating system/browser that he use or for creating web application that collect web surfers statistical data.

Here's how to use Detector library :

PHP:
  1. require('detector.php');
  2. $dip = &new Detector($_SERVER["REMOTE_ADDR"], $_SERVER["HTTP_USER_AGENT"]);
  3.  
  4. echo "$dip->town";
  5. echo "$dip->state, $dip->ccode,$dip->town, ($dip->ipaddress) ";
  6. echo "using : $dip->browser $dip->browser_version on $dip->os $dip->os_version";

The live demo of Detector library in action can be viewed here : Detector Library demo.

Requirements

  1. Requires PHP 4.4.0 or 5.0.x
  2. Requires php cURL extension installed, please refer here for workaround if your server doesn't have PHP cURL extension installed

License
Detector library is licensed under Creative Commons Attribution-ShareAlike 3.0, and can be modified and used in commercial application as long as you share the modified source code with the public.

Tags: , , , , , ,

Bookmark Post:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • NewsVine
  • Reddit
  • Netvouz
  • Spurl
  • Furl
  • digg
  • YahooMyWeb
  • del.icio.us

Posted in Uncategorized |

Related Posts

11 Responses

  1. Nick Says:

    I’m not following how to get the city, state, and zip. After running your sample code, here is what I am receiving:

    , ,, (74.135.147.136) using : Mozilla Firefox 1.5.0.12 on Mac OS Object>os_version

  2. Jon Moffet Says:

    that’s funny. btw you computer must be connected to the internet when you run the application.

    also may i know your php version?

  3. Nick Says:

    Yes, we are connected to the internet here at the office. The PHP is version 4.4.4

  4. What style is best to use for screenshots? Says:

    Kramer auto Pingback[...] the screenshots page I'm going to find out how to detect which OS the user is using (with PHP) so the user will see the screenshots by default in his "own" [...]

  5. Hermes Says:

    New BraunfelsTX, US,New Braunfels, (xxx.xxx.xxx.xxx) using : Mozilla Firefox 2.0.0.6 on Windows XP

    Worked great! Thanks SO MUCH for putting this out there.

  6. aldrin Says:

    wow…nice one!

  7. Phil Says:

    Been using this for my web counter for the last month or so; brilliant script thanks. Doesn’t appear to be working today though - your “Detector Library Demo” link isn’t working either. Any idea what the problem is?
    Thanks,
    Phil Kynaston

  8. Jon Moffet Says:

    random server maintenance i guess. It’s running fine now :)

  9. Charles Says:

    How to change Windows NT 6.0 to Windows Vista ?

  10. Addy Says:

    what this mean? can we change into ours?

    $apiserver=”http://showip.fakap.net/txt/”;

  11. Quick PHP Code Tips and Examples Feedage.com Says:

    Kramer auto Pingback[...] Tue, 15 May 2007 23:45:18 -0500 The practitioner of artificial intelligence and machine learning algorithm will recognize Naive Bayesian as one of the technique use to construct intelligent web application. Naive Bayesian is widely use as an intelligent classifier utilized to automatically classfies data based on statistical probability. Among the immediate use of Naive Bayesian technique is the classification of (spam) emails, [...] Detect ip location, operating system and browser using PHP Detector Library [...]

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.