You are here

function webform_protected_downloads_session_update in Webform Protected Downloads 7

Same name and namespace in other branches
  1. 6 webform_protected_downloads.page.inc \webform_protected_downloads_session_update()

Create or update the session info used to grant access and keep track of access expiration

Parameters

object $node:

string $hash:

1 call to webform_protected_downloads_session_update()
webform_protected_downloads_download_page in ./webform_protected_downloads.page.inc
Displays the download page

File

./webform_protected_downloads.page.inc, line 173

Code

function webform_protected_downloads_session_update($node, $hash) {

  // check that the session variable is correctly initialized
  if (!isset($_SESSION[WEBFORM_PROTECTED_DOWNLOADS_SESSION_KEY])) {
    $_SESSION[WEBFORM_PROTECTED_DOWNLOADS_SESSION_KEY] = array();
  }

  // if this is the first time, we need to add the hash to the session
  if (!isset($_SESSION[WEBFORM_PROTECTED_DOWNLOADS_SESSION_KEY][$hash])) {

    // get the expiration in seconds for the session
    $session_expires = webform_protected_downloads_get_configuration($node->nid, 'expiration_session', WEBFORM_PROTECTED_DOWNLOADS_DEFAULT_EXPIRATION_SESSION);

    // register this hash in the session
    $_SESSION[WEBFORM_PROTECTED_DOWNLOADS_SESSION_KEY][$hash] = array(
      'expires' => $session_expires > 0 ? time() + $session_expires : 0,
      'nid' => $node->nid,
    );
  }
}