tags:

views:

239

answers:

4
+8  A: 
echo $_SERVER['REMOTE_ADDR'];

http://php.net/manual/en/reserved.variables.server.php

lemon
Actually i want to know the IP address of the Client who is using my website. Not the server IP addresss where my pages have uploaded or executing..Please help me.
Anup Prakash
@Anup Prakash This is it – hence the "REMOTE" (from the perspective of the script).
Artefacto
+1  A: 

The answer is to use $_SERVER variable like this: $_SERVER["REMOTE_ADDR"] to give you the IP address of the client computer.

kainosnous
great one! thanx
Anup Prakash
A: 
function getip() {
    print "IP = ".$_SERVER["REMOTE_ADDR"];
}

getip();
Karandeep Singh
+3  A: 

Whatever you do, make sure not to trust data sent from the client. $_SERVER['REMOTE_ADDR'] contains the real IP address of the connecting party. That is the most reliable value you can find.

However, they can be behind a proxy server in which case the proxy may have set the $_SERVER['HTTP_X_FORWARDED_FOR'], but this value is easily spoofed. For example, it can be set by someone without a proxy, or the IP can be an internal IP from the LAN behind the proxy.

This means that if you are going to save the $_SERVER['HTTP_X_FORWARDED_FOR'], make sure you also save the $_SERVER['REMOTE_ADDR'] value. E.g. by saving both values in different fields in your database.

Emil Vikström
I was Busted........ :) thanks for correcting me Emil
OM The Eternity
not at all. you really give me a good funtion. So thanx again to see you back.
Anup Prakash