Screen Shot for Thumnbails


Conn Warwicker



Portfolio

Scripts and Websites I've made using PHP and MySQL mainly.

Snippets

Code snippets and mini tutorials

Contact

Contact me if you have any questions or queries



Home / Snippets / ip_address

This section is new and undergoing snippet addition, as of 13/6/11

IP Address



Getting the IP address in PHP is pretty easy:

<?php
$ip = $_SERVER['REMOTE_ADDR'];
?>


Though that can be faked or it could be hidden behind a proxy server. So you could try something like:

<?php
function getIP() 
{
	if(isset($_SERVER['HTTP_CLIENT_IP']))
	{
            $ip = $_SERVER['HTTP_CLIENT_IP'];
	}
	elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) 
	{
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
	} 
    else
    {
            $ip = $_SERVER['REMOTE_ADDR'];
	}
	list($ip) = explode(',',$ip);
	return $ip;
}
?>


If you wanted to try and sniff out the real IP address. It won't necessarily work though every time though, you may still get the proxy's IP address.

Leave a Comment


Comment

All fields are required

Your Name


Your Email Address


Your Comment


Human Validation

What animal is this above:






Comments


No Comments Have Been Made