detect pc's IP address using PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thematrixuum
Forum Newbie
Posts: 1
Joined: Sat Jul 21, 2007 4:14 am

detect pc's IP address using PHP

Post by thematrixuum »

anybody know how to code this function?

thanks..
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

The webserver's or the client's ip?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

There's no function.

Look in $_SERVER. Also note that if you're going to do something with the client IP it's unreliable to use.
philc
Forum Newbie
Posts: 9
Joined: Sat Jul 21, 2007 3:48 am

Post by philc »

this code stores the user's ip into a variable called var_ip

Code: Select all

$var_ip = $_SERVER['REMOTE_ADDR'];
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

It should be noted that $_SERVER['REMOTE_ADDR'] is not always set and will leave ugly NOTICE's on your page in the event that it isn't set (depending on your display_error configuration).

It would be wise to check for the existance of it first.

Code: Select all

if(!empty($_SERVER['REMOTE_ADDR']))
{
    $ip = $_SERVER['REMOTE_ADDR'];
} else
{
    //$_SERVER['REMOTE_ADDR'] not set
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply