Generating authentication header with PHP

10 views
Skip to first unread message

luke.pa...@gmail.com

unread,
Nov 5, 2008, 5:05:40 PM11/5/08
to Zeep Mobile
Here's a PHP example of generating the authentication header. It was
provided by Sam from http://www.shizzow.com. Thanks, Sam!

If you're using PHP and need help, give this a try and let us know how
it turns out, we haven't tested it ourselves
yet.


#!/usr/local/php5/bin/php -q
<?php
$API_KEY = "your_api_key";
$SECRET_ACCESS_KEY = "your_secret_key";
// you might think you could use the PHP const DATE_RFC1123 but it is
defined as "D, d M Y H:i:s O"
$http_date = gmdate("D, d M Y H:i:s T");
// (ex. Sat, 12 Jul 2008 09:04:28 GMT)

$parameters = "user_id=1234&body=" . urlencode("Art thou not Romeo,
and a Montague?");
//user_id=1234&body=Art+thou+not+Romeo%2C+and+a+Montague%3F

$canonical_string = $API_KEY . $http_date . $parameters;
$b64_mac = base64_encode(hash_hmac('sha1', $canonical_string,
$SECRET_ACCESS_KEY,true));

$authentication = "Zeep " . $API_KEY . ":" . $b64_mac;

echo($authentication);
?>
Reply all
Reply to author
Forward
0 new messages