1. Computing & Technology

Discuss in my forum

What Is My IP?

By , About.com Guide

Show your user's their IP address:

Retrieving the user's IP address is actually much simpler than you might think, and can be done in a single line. Getenv("REMOTE_ADDR") will return the IP address of the person visiting your site. Generally this is accurate, however if the user is running through a proxie server, then it will return the address of the proxie.

In this example, we retrieve the user's IP and then simply echo it's value back to the user.

<?php 
 //Gets the IP address
 $ip = getenv("REMOTE_ADDR") ; 
 Echo "Your IP is " . $ip; 
 ?> 

Have something to add? A bit of code? A suggestion of how to use it? View Reader Responses!

©2012 About.com. All rights reserved.

A part of The New York Times Company.