0

i am accessing webserver via Internet and not via local network then how to i get the ip address of my local system i am already try this with

GATEWAY_INTERFACE = <?php echo $_SERVER['GATEWAY_INTERFACE']; ?> <br> SERVER_ADDR = <?php echo $_SERVER['SERVER_ADDR']; ?> <br> SERVER_NAME = <?php echo $_SERVER['SERVER_NAME']; ?> <br> SERVER_SOFTWARE = <?php echo $_SERVER['SERVER_SOFTWARE']; ?> <br> SERVER_PROTOCOL = <?php echo $_SERVER['SERVER_PROTOCOL']; ?> <br> REQUEST_METHOD = <?php echo $_SERVER['REQUEST_METHOD']; ?> <br> REQUEST_TIME = <?php echo $_SERVER['REQUEST_TIME']; ?> <br> QUERY_STRING = <?php echo $_SERVER['QUERY_STRING']; ?> <br> DOCUMENT_ROOT = <?php echo $_SERVER['DOCUMENT_ROOT']; ?> <br> HTTP_ACCEPT = <?php echo $_SERVER['HTTP_ACCEPT']; ?> <br> HTTP_ACCEPT_CHARSET = <?php echo $_SERVER['HTTP_ACCEPT_CHARSET']; ?> <br> HTTP_ACCEPT_ENCODING = <?php echo $_SERVER['HTTP_ACCEPT_ENCODING']; ?> <br> HTTP_ACCEPT_LANGUAGE = <?php echo $_SERVER['HTTP_ACCEPT_LANGUAGE']; ?> <br> HTTP_CONNECTION = <?php echo $_SERVER['HTTP_CONNECTION']; ?> <br> HTTP_HOST = <?php echo $_SERVER['HTTP_HOST']; ?> <br> HTTP_REFERER = <?php echo $_SERVER['HTTP_REFERER']; ?> <br> HTTP_USER_AGENT = <?php echo $_SERVER['HTTP_USER_AGENT']; ?> <br> HTTPS = <?php echo $_SERVER['HTTPS']; ?> <br> REMOTE_ADDR = <?php echo $_SERVER['REMOTE_ADDR']; ?> <br> REMOTE_HOST = <?php echo $_SERVER['REMOTE_HOST']; ?> <br> REMOTE_PORT = <?php echo $_SERVER['REMOTE_PORT']; ?> <br> SCRIPT_FILENAME = <?php echo $_SERVER['SCRIPT_FILENAME']; ?> <br> SERVER_ADMIN = <?php echo $_SERVER['SERVER_ADMIN']; ?> <br> SERVER_PORT = <?php echo $_SERVER['SERVER_PORT']; ?> <br> SERVER_SIGNATURE = <?php echo $_SERVER['SERVER_SIGNATURE']; ?> <br> PATH_TRANSLATED = <?php echo $_SERVER['PATH_TRANSLATED']; ?> <br> SCRIPT_NAME = <?php echo $_SERVER['SCRIPT_NAME']; ?> <br> REQUEST_URI = <?php echo $_SERVER['REQUEST_URI']; ?> <br> PHP_AUTH_DIGEST = <?php echo $_SERVER['PHP_AUTH_DIGEST']; ?> <br> PHP_AUTH_USER = <?php echo $_SERVER['PHP_AUTH_USER']; ?> <br> PHP_AUTH_PW = <?php echo $_SERVER['PHP_AUTH_PW']; ?> <br> AUTH_TYPE = <?php echo $_SERVER['AUTH_TYPE']; ?> <br> ( and ) <html> <head> <title>What is my IP address?</title> </head> <body> <?php if (getenv(HTTP_X_FORWARDED_FOR)) { $pipaddress = getenv(HTTP_X_FORWARDED_FOR); $ipaddress = getenv(REMOTE_ADDR); echo "Your Proxy IPaddress is : ".$pipaddress. "(via $ipaddress)" ; } else { $ipaddress = getenv(REMOTE_ADDR); echo "Your IP address is : $ipaddress"; } ?> </body> </html> 

but no use it just give the server Ip. Please guide me

2
  • $_SERVER['REMOTE_ADDR'] will give the client's IP address. I don't understand the problem. Commented Dec 16, 2010 at 3:59
  • Copy of link below. You previously asked this and no one could answer. Perhaps you could clarify exactly what you are looking for and what is going on? stackoverflow.com/questions/4447716/… Commented Dec 16, 2010 at 4:05

1 Answer 1

0

$_SERVER['REMOTE_ADDR'] will not work on load balanced sites. For that, and other different situations, use this class:

http://brettic.us/code/php-codeigniter-remote-ip-from-load-balancer/

 class RemoteIP { function ip_address() { if ($this->ip_address !== FALSE) { return $this->ip_address; } if ($this->server('HTTP_X_CLIENTIP')) { $this->ip_address = $_SERVER['HTTP_X_CLIENTIP']; } elseif ($this->server('REMOTE_ADDR') AND $this->server('HTTP_CLIENT_IP')) { $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; } elseif ($this->server('REMOTE_ADDR')) { $this->ip_address = $_SERVER['REMOTE_ADDR']; } elseif ($this->server('HTTP_CLIENT_IP')) { $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; } elseif ($this->server('HTTP_X_FORWARDED_FOR')) { $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; } if ($this->ip_address === FALSE) { $this->ip_address = '0.0.0.0'; return $this->ip_address; } if (strstr($this->ip_address, ',')) { $x = explode(',', $this->ip_address); $this->ip_address = end($x); } if ( ! $this->valid_ip($this->ip_address)) { $this->ip_address = '0.0.0.0'; } return $this->ip_address; } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.