Generating an HMAC-MD5 hash using PHP 5

The following sample code…

  • generates a UNIX timestamp (UTC)
  • builds the query string
  • generates an HMAC-MD5 hash of the string
  • appends the query string and hash to the completion notification URL
$shared_key = 'xxxxxxxx'; // your shared key, supplied by your account manager
$tp_aid = 'xxxxxxxx';  // your advertiser ID, supplied by your account manager
$tp_sid = $_REQUEST['sub_id']; // customer click ID, 'sub_id' is the parameter used to pass you the click ID in this example
$tp_t = time(); // current unix-time in seconds.
$query = "tp_aid=$tp_aid&tp_sid=$tp_sid&tp_t=$tp_t"; // query string to be signed
$actualHash = hash_hmac("md5", $query, $shared_key);
$completion_notification_url = "https://tpc.trialpay.com/?$query&tp_v1=$actualHash";