<?php
function get_location($url)
{
  $headers = get_headers($url, 1);
  
  if(isset($headers['Location'])){
  	if(is_array($headers['Location'])){
  		return array_pop($headers['Location']);						
  	}else{
  		return $headers['Location'];					
    }
  }else{
  	return $url;
  }  
}