View Full Version : code for getting IP address and system time

02-21-2010, 12:24 PM
in my php page i have added code for getting IP

if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy

but i am not getting the real IP . HOW TO GET THE REAL IP ??
give me a solution..

i have got one more problem..
to get the system date and time .added the following

$date = date(' d/m/Y h:i:s A');

but the time am getting is 3 hours behind the system time , i need to get the system time , how??
suggestions plz...thank u..

02-21-2010, 01:03 PM
Just a few notes:

$_SERVER['HTTP_CLIENT_IP'] contains the "Client-Ip" HTTP header and could be forged.

$_SERVER['HTTP_X_FORWARDED_FOR'] contains "X-Forwarded-For (http://en.wikipedia.org/wiki/X-Forwarded-For)" header and could be forged.

One could send any of these 2 headers e.g. with header(). Both $_SERVER['HTTP_CLIENT_IP'] and $_SERVER['HTTP_X_FORWARDED_FOR'] are not really reliable.

As to the date() function, you could need to set the time zone in the way it could be necessary. For PHP5 date_default_timezone_set() (http://php.net/date_default_timezone_set) could be used.

02-21-2010, 01:05 PM
I normally use:

$user_ip = $_SERVER['REMOTE_ADDR']; for user IP


$date = date('m/d/Y')." at ".date('g:i.s')." ".date('a');

For a Timestamp with date and time.

Hope this helps!

02-22-2010, 08:26 AM
thank you for the suggestions , it worked ,
Thanks a lot.