PHP signing code

function sign_url($url, $key, $secret)
{
    $url = urldecode($url);

    if (strpos($url,'?') !== false)
    {
    	$url .= "&";
    }
    else
    {
    	$url .= "?";
    }
    $url .= "ApplicationKey=" . $key;

    $signature = hash_hmac("sha1", $url, $secret);
    $url .= "&Signature=" . hex_to_base64($signature);

    return $url;
}

function hex_to_base64($hex){
  $return = '';
  foreach(str_split($hex, 2) as $pair){
    $return .= chr(hexdec($pair));
  }
  return base64_encode($return);
}