Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple ip question 1

Status
Not open for further replies.

rbauerle

Programmer
Oct 16, 2001
48
BR
How do I get the user's ip address?

Tks.
 
Usually:
$_SERVER['REMOTE_ADDR']

However, there could be X_FORWARDED_FOR values etc. for proxied requests. IP is not telling you much - also remember that IPv4 is not spoof-proof.
 
If you want the IP and Host :

if (getenv("HTTP_X_FORWARDED_FOR")){
$ip=getenv("HTTP_X_FORWARDED_FOR");
} else {
$ip=getenv("REMOTE_ADDR");
}
$hostname = gethostbyaddr($ip);

Here ,

$hostname : display user's hostname
$ip : display user's ip
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top