ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Internet & the Web

Show your visitors IP address

Updated on January 25, 2013

There are many instances were a webmaster/blogger might want to display the IP addresses of their visitors on a particular page, and for a number of reasons. It can, for example help to minimise fraud and help ban spammers and malicious people from your site by identifying their IP addresses. Or you can use it to get to know the location of your specific visitors. The applications are quite many and vary depending on what you want to use the addresses for.

In this hub/article I will provide you with the necessary code, (in multiple scripting languages) that you can implement into webpages on your website in order to, like the title of the article says, display your visitor's Ip address.

Before I continue, I would like to note that this hub is targeted towards users who are at least experienced or knowledgeable in basic scripting/programming languages. ASP, Java and PHP to be specific. If you are not familiar with any of these, I highly recommend you learn them before you attempt to use any of the code I will provide you. (Don't worry, they don't take that long to learn.)

Alright, now that you understand what this article is about, lets get right to the coding:

Scan through the following and copy and paste whichever code/language best suits your current needs. Don't forget to include their respective opening and closing tags when implementing them into your webpage(s).

Javascript code:

var ip= '<!--#echo var="REMOTE_ADDR"-->';

document.write("Your IP Address is :"+ip+" ");

ASP code:


PHP code:


$remote_address = getenv("REMOTE_ADDR");

echo "Your IP address is $remote_address.";

$browser_type = getenv("HTTP_USER_AGENT");

echo "You are using $browser_type.";


Note: To assure cross-browser compatibility when implementing the javascript code, you should use a web server capable of running SSI (most web servers do this by default).You might want to further ensure compatibility by making sure the page the javascript code is implemented has a .shtml suffix in order to tell the server to parse it properly.


    0 of 8192 characters used
    Post Comment

    • profile image

      geolify 3 years ago

      if you need accurate location from IP address you can use this tool called Geolify.

      Check out