Query String Authentication in PHP

To allow users access to files stored with Amazon using Amazon Web Services, or AWS, with PHP, you must create a query string that can be authenticated by AWS. The process for creating a proper query string is somewhat complex and you should read the documentation carefully to make sure you include all the necessary elements. Instead of writing your own function, you may want to use the library provided by AWS that handles much of the back-end setup of a proper query string.

  1. Sort Query Parameters

    • Amazon query string authentication in PHP requires that the parameters in the query string be sorted. The easiest way to do this is to create an array of parameters, use the "ksort" function to sort the array, and put the query string back together in order after you've added all the fields required by AWS authentication.

    Set Expiration Time

    • When authenticating a query string with PHP and AWS, you have to pass a time stamp indicating the expiration time of the query and your AWS access key. You can optionally pass a version number of the service you are using. The time stamp parameter is named "Timestamp," the access key parameter is named "AWSAccessKeyId" and the version parameter is named "Version."

    Create Encrypted Signature

    • An AWS query string authentication requirement with PHP is that you encrypt the signature with your secret key by creating a keyed hash value, encoding it to base 64 and url-encoding the result. Use the "hash_hmac" function to create the keyed hash value with encryption such as "sha1" or "sha256"; the "base64_encode" function to encode the result to base 64; and the "urlencode" function to url-encode the result.

    AWS SDK for PHP

    • Amazon provides an AWS Software Development Kit, or SDK, for PHP that helps make the query string authentication process easier. The SDK hides most of the authentication requirements in an application programming interface so you can pass the required parameters and allow the predefined functions to encode and format the query properly. Download the AWS PHP SDK at http://aws.amazon.com/sdkforphp/.

Related Searches:

References

Resources

Comments

Related Ads

Featured