Function for get client pc ip address

Mahabubur Rahman
2
Today i discus on "how to get client pc ip address using PHP". Some time we need to get client pc ip address for security or other validation. Such as the voting system on online newspaper. Every day newspaper get only one vote form a ip address. So we need to get client ip address some time for some specific development purpose.

To get client ip address i create a function as following.
<?php
 function getClientIpAddress()
{
  if (!empty($_SERVER['HTTP_CLIENT_IP']))
  {
  $ipadd=$_SERVER['HTTP_CLIENT_IP'];/*check ip from internet*/
  }
  elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
  {
  $ipadd=$_SERVER['HTTP_X_FORWARDED_FOR'];/*check ip proxy*/
  }
  else{
  $ipadd=$_SERVER['REMOTE_ADDR'];
  }
  return $ipadd;
}
echo getClientIpAddress(); // display IP address?>

now test the code and enjoy it.
for any question  
Tags

Post a Comment

2Comments
Post a Comment