Ejemplo n.º 1
0
 public static function ensureSession()
 {
     $session_id = session_id();
     if (empty($session_id)) {
         // Expand session lifetime
         ini_set("session.gc_maxlifetime", 24 * 60 * 60);
         // Instantiate the Amazon DynamoDB client.
         // REMEMBER: You need to set 'default_cache_config' in your config.inc.php.
         $dynamodb = new AmazonDynamoDB();
         // Register the DynamoDB Session Handler.
         $handler = $dynamodb->register_session_handler(array('table_name' => 'internationalize-sessions', 'session_lifetime' => 0, 'session_locking' => false));
         session_start();
     }
 }
	* You've already added your credentials to your config.inc.php file, as per the
	  instructions in the Getting Started Guide.

	* You've already created a table in Amazon DynamoDB called "sessions-test" with
	  a string primary key called "id".

	TO RUN:
	* Run this file on your web server by loading it in your browser. It will
	  generate HTML output.
*/
// Include the SDK
require_once dirname(dirname(__FILE__)) . '/sdk.class.php';
// Instantiate a DynamoDB client
$dynamodb = new AmazonDynamoDB();
// Instantiate, configure, and register the session handler
$session_handler = $dynamodb->register_session_handler(array('table_name' => 'sessions-test', 'lifetime' => 3600));
// Open the session
session_start();
// If the logout flag is set, do a logout instead
if (isset($_GET['logout'])) {
    // Destroy the session
    session_destroy();
    // Refresh this page to show the login form
    header('Location: html-dynamodb_sessions_login.php');
    exit(0);
}
// Simulate authentication by checking for username and password
if (isset($_POST['username']) && isset($_POST['password'])) {
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
    if (!empty($username) && !empty($password)) {