DigitCodes

Coding Notes


Follow @afsalrahim
  • PHP Codes
  • Web Design
    • CSS Tricks
  • WordPress
    • WordPress Tips
    • WordPress Themes
    • WordPress Plugins
  • Blogging
You are here: Home / PHP Codes / Show user information like IP address, useragent with PHP codes

Show user information like IP address, useragent with PHP codes

November 28, 2012 by Afsal Rahim 4 Comments

Show user information like IP address, useragent with PHP codes

[adslot]

You might have seen some of the sites showing you the  information like “Your IP address  is 127.0.0.1 ” or “You are using Firefox browser” etc. Its really easy to display or get these user or visitor information using PHP codes. Here in this post, we will write a simple php code for displaying a visitor’s IP address, browser info and where that user came from (Http_Referrer i.e from which url the user clicked to get to your current page). This will be useful for you to keep track of your visitors or optimize the webpage for your users in a specific way depending on the browser or ip address etc.

PHP Code

PHP Code Output

Visitor IP address:
127.0.0.1

Browser (User Agent) Info:
Mozilla/5.0 (Windows NT 6.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1

Referrer:
http://www.wapguy.com

Its really a simple PHP code, but still useful for you to track your website visitors and provide a better web browsing experience for them.

Filed Under: PHP Codes

Comments

  1. Aayush Atharva says

    November 19, 2016 at 9:50 am

    Thanks A Lot Man !

    Reply
  2. Zoé says

    January 11, 2018 at 9:17 am

    There is something wrong here, variable $referred is not declared:

    $referrer = $_SERVER[‘HTTP_REFERER’];
    if ($referred == “”) {
    $referrer = “This page was accessed directly”;
    }

    Thanks for the examples though!

    Reply
  3. null says

    January 16, 2018 at 12:24 am

    $referrer != $referred

    Reply
  4. Barry Squatter says

    July 10, 2018 at 9:10 am

    and dont forget this one 🙂

    $hostname = @gethostbyaddr($ip);

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Sponsered

FREE Email Updates

Subscribe to our newsletter to get all the latest updates to your inbox..!



TRENDING

Add a Stylish Email Subscription Form for your Blog

How to Add Your Custom Logo to WordPress Login Screen?

Free HTML5 Responsive WordPress Theme : SimpleCorp

How you can make a stylish Facebook Like Box with simple CSS tricks

Return to top of page

Copyright © 2016 · digitcodes.com · Privacy Policy · Contact Us