Learn WordPress
Home » Script

Display Visitor IP Address and Host Name Using Javascript

IP Address

If you want to display your visitor IP address and visitor host name into your website, there’s only simple javascript to use.

Here’n the reason why these script is simple:

  1. I proud to you a free and simple JavaScript script to tell your visitors what their IP addresses and Host names are. The IP displayed to the users at your desired location on your Web pages area.
  2. The client IP address is stored in variable “VIH_HostIP”. The client host name, if available, is stored in variable “VIH_HostName”. You can use these variables in your own JavaScript code, if desired.
  3. You can omit the “VIH_BackColor”, “VIH_ForeColor”, “VIH_FontPix”, “VIH_DisplayFormat”, and “VIH_DisplayOnPage” parameters. Default values will be used in that case.
  4. “VIH_DisplayFormat” allows you to format the display to your liking. For example, instead of the default English, you can use terms from your own language, or make any other desired adjustments, like omitting the IP address.
  5. If “VIH_DisplayOnPage” is set to “no”, client information will not be printed. This option is useful if you want to use your own JavaScript code utilizing the “VIH_HostIP” and/or “VIH_HostName” variables.

The syntax.
OK, let’s start the code, you just need to copy and paste this simple code around the area where you want to display the IP address and host name.

  1. The 1st code:
    The syntax on how to reference a PHP file using external JavaScript is enough consistents with what you already know:

    <script type="text/javascript" src="your-script-file.php"></script>

    where your “your-script-file.php” is either an absolute and relative path to a PHP script instead of the usual .js file. Pass parameters to the PHP script through the URL string:

    Here’s a basic example of a php script- your-script-file.php- being called by external JavaScript to do something that JavaScript alone can’t and save as your-script-file.php for example I save as ip.php

    <?
    //"ip.php" example- display user IP address on any page
    Header("content-type: application/x-javascript");
    $serverIP=$_SERVER[‘REMOTE_ADDR’];
    echo "document.write(\"Your IP address is: <b>" . $serverIP . "</b>\")";
    ?>

    Once called by external JavaScript:

    <script type=”text/javascript” src=”http://www.aming.info/script/ip.php”></script>

    it will looks like:

  2. The 2nd code:

    <script language="javascript">

    //IP address display: By http://www.Hostroute.com
    //Script featured on JavaScript Kit (http://www.javascriptkit.com)

    var ip = ‘<!–#echo var="REMOTE_ADDR"–>’

    function ipval() {
    document.myform.ipaddr.value=ip;
    }
    window.onload=ipval
    </script>

    <form method="post" action="" name="myform">
    <input type="text" name="ipaddr" readonly>
    </form>

    it will looks like:


  3. The 3rd code:

    <script language="JavaScript">
    VIH_BackColor = "white";
    VIH_ForeColor = "navy";
    VIH_FontPix = "16";
    VIH_DisplayFormat = "You are visiting from IP Address: %%IP%%<br>Host: %%HOST%%";
    VIH_DisplayOnPage = "yes";
    </script>
    <script language="JavaScript" src="http://www.aming.info/script/clientip.js.php"></script>

    it will looks like:


2 Comments

  • Simple Domains says:

    hey there and thanks in your information ? I’ve definitely picked up anything new from right here. I did then again expertise several technical points the usage of this website, since I skilled to reload the site many occasions previous to I may get it to load properly. I have been considering if your hosting is OK? Now not that I am complaining, but sluggish loading cases occasions will often impact your placement in google and can injury your quality rating if ads and marketing with Adwords. Well I’m adding this RSS to my email and can look out for much more of your respective interesting content. Make sure you update this again soon..

  • Justin says:

    I usually don’t take the time to post but this info compelled me to, thank you for the info

FREE Cloud Storage