How to Get Real IP Address of Client In PHP

To getting the Real IP Address of client in PHP is very simple using following function, even if user is behind a proxy server.

function getRealIpAddressOfClient()
{
  if (!empty($_SERVER[‘HTTP_CLIENT_IP’]))
  {
    $ip_address=$_SERVER[‘HTTP_CLIENT_IP’];
  }
  else if (!empty($_SERVER[‘HTTP_X_FORWARDED_FOR’]))
//check IP is pass from proxy
  {
    $ip_address=$_SERVER[‘HTTP_X_FORWARDED_FOR’];
  

Read More

Detect AJAX Request in PHP

Most of the JavaScript frameworks like jQuery, mootools send and additional HTTP_X_REQUESTED_WITH header when they make an AJAX request, so that you can detect AJAX request on server side.

if(!empty($_SERVER[‘HTTP_X_REQUESTED_WITH’])
&& strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’]) == ‘xmlhttprequest’)
{
  //If AJAX Request Then 
} else { 
  //something else 
}

For More Info http://davidwalsh.name/detect-ajax

Read More