require_once '/usr/share/php/AWSSDKforPHP/sdk.class.php'; define('AWS_KEY', 'AKIAIGKECZXA7AEIJLMQ'); define('AWS_SECRET_KEY', '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'); define('AWS_ACCOUNT_ID', '457964863276'); # for testing the conditional put $timeout = isset($_GET['timeout']) ? (int) $_GET['timeout'] : 0; $sdb = new AmazonSDB(); # $sdb->set_region($sdb::REGION_EU_W1); $accounts = $sdb->create_domain('accounts'); $accounts->isOK() or die('could not create domain accounts'); # we have to be a bit persistent; even though it # is unlikely someone else might have incremented # during our operation do { $response = $sdb->get_attributes('accounts', '*****@*****.**', 'PDFs'); $PDFs = (int) $response->body->Value(0); # convenience measure for testing sleep($timeout); $account = array('PDFs' => sprintf('%05d', $PDFs + 1)); $response = $sdb->put_attributes('accounts', '*****@*****.**', $account, true, array('Expected.Name' => 'PDFs', 'Expected.Value' => sprintf('%05d', $PDFs))); } while ($response->isOK() === FALSE); # to read the value we have to force a consistent read $response = $sdb->get_attributes('accounts', '*****@*****.**', 'PDFs', array('ConsistentRead' => 'true')); pr((int) $response->body->Value(0)); function pr($var) { print '<pre>'; print_r($var); print '</pre>'; }
<?php // Set the response class on a new AmazonSDB object $sdb = new \AmazonSDB(); $sdb->set_response_class('\\ORM\\SDB\\SDBResponse'); // --------------------- // Using get_attributes() (retrieves one item's attributes) $attributes = $sdb->get_attributes('myDomain', 'item1'); // You can still use CFResponse features if (!$attributes->isOK()) { die("Oh no! There's a problem"); } // $attributes is now accessible as an array of key->value pairs associated with item1 echo "My item {$attributes['id']} has the name {$attributes['name']}"; // ------------- // Using select() (retrieves any number of items) $items = $sdb->select('SELECT * FROM myDomain'); // Count will work echo "Returned ", count($items), " items."; foreach ($items as $itemName => $itemAttributes) { echo "Item: {$itemName}\n"; // Print out all the attributes of this item print_r($itemAttributes); }
<?php require_once './sdk.class.php'; error_reporting(-1); ini_set('display_errors', true); header("Content-type: text/html; charset=utf-8"); $sdb = new AmazonSDB(); $domain = 'authors'; $uname = $_POST["name"]; $email = $_POST["email"]; $pass = $_POST["pass"]; $type = $_POST["type"] == "Reader" ? "2" : "1"; //reader->2 author->1 if ($uname && $email && $pass) { $response = $sdb->get_attributes($domain, $email); if ($response->body->GetAttributesResult->Attribute) { echo "already registered"; } else { $response = $sdb->put_attributes($domain, $email, array('name' => $uname, 'password' => md5($pass), 'type' => $type)); if ($response->isOK()) { session_start(); $_SESSION['ucmsg'] = "User created."; } else { session_start(); $_SESSION['uemsg'] = "User creation failed."; } header('Location:admin.php'); } }
<?php require_once '/usr/share/php/AWSSDKforPHP/sdk.class.php'; define('AWS_KEY', 'AKIAIGKECZXA7AEIJLMQ'); define('AWS_SECRET_KEY', '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'); define('AWS_ACCOUNT_ID', '457964863276'); $sdb = new AmazonSDB(); # $sdb->set_region($sdb::REGION_EU_W1); $accounts = $sdb->create_domain('accounts'); $accounts->isOK() or die('could not create domain accounts'); $response = $sdb->get_attributes('accounts', '*****@*****.**'); pr($response->body); function pr($var) { print '<pre>'; print_r($var); print '</pre>'; }
<?php require_once './sdk.class.php'; error_reporting(-1); ini_set('display_errors', true); header("Content-type: text/html; charset=utf-8"); $sdb = new AmazonSDB(); $domain = 'authors'; $email = $_POST["email"]; $pass = $_POST["pass"]; $response = $sdb->get_attributes($domain, $email, array('name', 'password', 'type')); if ($response->body->GetAttributesResult->Attribute) { $uname = $response->body->GetAttributesResult->Attribute[0]->Value; $utype = $response->body->GetAttributesResult->Attribute[1]->Value; var_dump($utype); if (md5($pass) == $response->body->GetAttributesResult->Attribute[2]->Value) { session_destroy(); session_start(); $_SESSION['auth'] = 1; $_SESSION['uname'] = (string) $uname; $_SESSION['utype'] = (string) $utype; $_SESSION['email'] = $email; if ((string) $utype == "2") { header("Location:index.php"); } if ((string) $utype == "1") { header("Location:author.php"); } else { header("Location:admin.php"); } } else {
<div class="navbar-inner"> <div class="container"><!-- Collapsable nav bar --> <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <a href="index.php"class="brand">Instabook</a> <? session_start(); //var_dump($_SESSION); ?> <? require_once './sdk.class.php'; //session_start(); $domain = 'books-aalr'; $sdb = new AmazonSDB(); $author = $_SESSION['email']; $result=$sdb->get_attributes($domain, $author,array('author','object')); //var_dump($result->body); ?> <div class="nav-collapse"> <ul class="nav pull-right"> <li> <?if(isset($_SESSION['auth'])){?> <p class="welcome">Welcome<strong> <?echo $_SESSION['uname'];?></strong></p> <?} else{ ?> <a href="signup.html">Sign Up</a> <?}?> </li>
public function testGetAttributesNoResult() { $result = $this->object->get_attributes(self::DOMAIN, 'item100'); $this->assertEquals(0, count($result)); }