How to Find an IP Address With HTML

Save

You may find it useful in Web programming to know the IP addresses of the visitors to your website. HTML alone does not have the proper functions to find a visitor's IP address, but you may embed a PHP function in your HTML code and use the two together to get IP addresses. Use the "getenv" function, which returns environment variables, such as the "REMOTE_ADDR" element, the IP address of the person viewing the HTML page.

  • Open the HTML file you in which you want to include a function that finds IP addresses. Insert the cursor where you want to display the visitor's IP address.

  • Type the following:

    <?php

    $IP = getenv(REMOTE_ADDR);

    echo "Your computer's IP address is : $IP";

    ?>

    This PHP tag gets the visitor's address and displays it on your HTML page. You may do other things with the address, such as saving it in a cookie or a database of visitors.

  • Save the HTML file and upload it to your Web server. The function does not work unless it is on the Internet.

References

Promoted By Zergnet

Comments

You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

M
Is DIY in your DNA? Become part of our maker community.
Submit Your Work!