0

I'm trying to create a signature request for amazon's AWS api using PHP. I'm not too familiar with PHP so this question might seem extremely obvious, so for that I'm sorry -

Amazon provides sample code for generating the signature request to use their API - which can be found here:

http://aws.amazon.com/code/AWIS/402

Their instructions state simply:

Run php urlinfo.php ACCESS_KEY_ID SECRET_ACCESS_KEY site

But I'm not sure how to "run" a php file. My instinct was to include the php file so I could make a call to its public urlInfo function:

UrlInfo($accessKeyId, $secretAccessKey, $site)

but if I include it:

<?php require_once ('urlinfo.php'); ?>

The page automatically generates the message:

Usage: ACCESS_KEY_ID SECRET_ACCESS_KEY site

So how do I call this php file from my index file and pass it the parameters it requires?

4 Answers 4

1

The urlinfo.php script was intended to be ran via PHP command line interface and expects arguments passed on via cli.

If you remove the following portion of the code:

if (count($argv) < 4) {
    echo "Usage: $argv[0] ACCESS_KEY_ID SECRET_ACCESS_KEY site\n";
    exit(-1);
}
else {
    $accessKeyId = $argv[1];
    $secretAccessKey = $argv[2];
    $site = $argv[3];
}

And then do:

$accessKeyId = "youkeyid";
$secretAccessKey = "yoursecret"; 
$site = "yoursite";

include('urlinfo.php');

It will work as expected.

1

Remove the following code at the bottom of the urlinfo.php file.

if (count($argv) < 4) {
    echo "Usage: $argv[0] ACCESS_KEY_ID SECRET_ACCESS_KEY site\n";
    exit(-1);
}
else {
    $accessKeyId = $argv[1];
    $secretAccessKey = $argv[2];
    $site = $argv[3];
}

$urlInfo = new UrlInfo($accessKeyId, $secretAccessKey, $site);
$urlInfo->getUrlInfo();

Then you can use the following the code to generate the urlinfo you need.

$urlInfo = new UrlInfo($accessKeyId, $secretAccessKey, $site);
$urlInfo->getUrlInfo();
1
  • So I guess I'm a little confused - wouldn't I need to run this every time I want to access the web service? What do I use as the "site" if I'm running this on localhost? Can I run it on localhost?
    – mheavers
    Oct 26, 2011 at 17:25
1

Assuming you have unix command line:

Type "which php" from the command line to see if your shell knows where your php bin file is. If you get a path, type that path to run the file followed by the parameters ACCESS_KEY_ID SECRET_ACCESS_KEY site

Example: /usr/local/bin/php urlinfo.php ACCESS_KEY_ID SECRET_ACCESS_KEY site


0

The instructions to run the file mean you should type that command into a command prompt.

The sample code is meant as just that, a sample. As such, they have tried to make it easy for you to run it without putting it into a web server. Instead you can just execute php directly on it.

If you want to run it in a web server, you will need to rewrite the example to do so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.