Hello Friends,

Good Morning,

I want in my website the visitor ip has to be shown or it log in seperate file.
As iam successful in doing that,
but my problem is iam not getting the exact IP Adress of the Host or visitor.
Please help me in finding the exact IP Address of the host or visitor.

My code

$logfile= 'ip.html';
$IP = $_SERVER['REMOTE_ADDR'];
$logdetails=  date("F j, Y, g:i a O T") . ': ' .
'<a href=http://www.geobytes.com/IpLocator.htm?GetLocation&ipaddress='.$_SERVER['REMOTE_ADDR'].'>'
.$_SERVER['REMOTE_ADDR'].'</a>';
$fp = fopen($logfile, "a"); 
fwrite($fp, $logdetails);
fwrite($fp, "<br>");
fclose($fp);

Please help in finding the exact ip address of the Visitor

Thank You

Your httpd access logs will have the IP address for every request to apache.

69.19.14.29 - - [11/Jul/2010:23:03:17 -0500] "GET /mdam.exe HTTP/1.1" 404 282
69.19.14.29 - - [11/Jul/2010:23:03:32 -0500] "GET /mdam.exe HTTP/1.1" 404 282
69.19.14.29 - - [11/Jul/2010:23:03:52 -0500] "GET /mdam.exe HTTP/1.1" 404 282
69.19.14.29 - - [11/Jul/2010:23:04:01 -0500] "GET / HTTP/1.1" 200 2433
69.19.14.29 - - [11/Jul/2010:23:04:02 -0500] "GET /mm_lodging1.css HTTP/1.1" 200 1289

Try This:

function getipaddress()
{
	if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
	{
		$ip = $_SERVER['HTTP_CLIENT_IP'];
	}
	else if (!empty($_SERVER['HTTP_CLIENT_IP']))
	{
		$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
	}
	else if (!empty($_SERVER['REMOTE_ADDR']))
	{
		$ip = $_SERVER['REMOTE_ADDR'];
	}
	else
	{
		die("If you are receiving this message, please contact the webmaster at ______________");
	}
	return $ip;
}

This code works just fine for my website. Although I don't have much use for it. I wanted to block specific IP address back when I started web programming. Then I realized that the IP addresses are not static.

I only remember one or two times this code failed to get the IP.

Good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.