Array

Array

Display Visitor IP Address and Host Name Using Javascript

Categorized | Script

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:


If you enjoyed for what you have search, come on Buy me a beer

Leave a Reply

Security Code:



Hostgator Unlimited Hosting coupon remove 25% for all plans

  • Latest
  • Comments
  • Tags
  • Subscribe
Advertise Here
Advertise Here

subscribe our newsletter





Powered by FeedBurner


Blogroll

Information