How to get user ip in php

get user IP address on visit, When user viewing your website, IP address is require to store like which country visit from? So simply add below code and get IP of visitor.

Create ipaddress.php file

$deep_detect=true;
$ip = $_SERVER["REMOTE_ADDR"];
if ($deep_detect) {
	if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP))
		$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
	if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP))
		$ip = $_SERVER['HTTP_CLIENT_IP'];
}

This code will gives you IP address of visitor.

Leave a Reply