Thursday, January 28, 2010

Retrieve the ip address with php

Sometimes is usefull to know the ip address of our website users, to do this we can use php.
To retrieve the ip address using php is necessary the specific environment variable.

The $_SERVER variable.

//this is the variable
$_SERVER['REMOTE_ADDR'] 

Inside this special variable there is the ip address of the user that open the page.

For example if we want print this variable this is the correct syntax:

//this print my ip address
echo $_SERVER['REMOTE_ADDR'];

Easy!!

No comments:

Post a Comment