PHP function to follow a redirected link to the final url