Sharebar?

Step 5: Redirect the user

The final step in processing an incoming LTI launch request is to redirect the user to the content page (e.g. resource or activity) which is the intended destination.  The URL for the location of this page may depend upon a number of factors, such as:

  • the ID of the resource link from which the launch originates;
  • whether this is the first launch from this resource link;
  • the role of the user;
  • the values of any custom parameters included in the launch message.

If the request is to be rejected then it is best practice to return the user to the tool consumer with a user-friendly error message.  If a return URL was not supplied by the tool consumer in the launch message, then a standalone error page should be used.  It is best not to redirect a user to a page which contains a login form since LTI users are not expected to have credentials to login directly to a tool provider - this is the purpose of using LTI!

At the end of this step, the user will have been either redirected to the relevant content page in the tool provider, or been given an error message.

Sample PHP Code

This code is provided for illustrative purposes only.  Successful requests are redirected to a page at welcome.php, whilst unsuccessful requests will be returned to the tool consumer if possible, otherwise to a page at error.php.  The error message displayed may be made more helpful but it should be remembered that it is for an end-user who has little control or knowledge of the LTI launch process.  Some LTI class libraries are known to replace the more generic error message with a more technical message if a custom parameter named custom_debug is included in the message with a value of true.  Alternatively (or in addition) the tool provider could return the more technical error message to be logged by the tool consumer (using the lti_errorlog query parameter).

The $ok variable is carried over from the previous steps and, at the start of this code segment, should have a value of true if the message has been accepted and false if it is to be rejected.

  // Set destination page
  if ($ok) {
    $page = 'welcome.php';
  } else {
    $page = getErrorPage('Sorry, an error occurred.');
  }

  // Perform redirect
  header("Location: {$page}");

getErrorPage Function

Get the page to redirect a user to when a launch error occurs.

  function getErrorPage($msg) {

    // Redirect back to the tool consumer with an error message if URL is available
    if (isset($_POST['launch_presentation_return_url']) && !empty($_POST['launch_presentation_return_url'])) {
      $page = $_POST['launch_presentation_return_url'];
      if (strpos($page, '?') === FALSE) {
        $page .= '?';
      } else {
        $page .= '&';
      }
      $page .= 'lti_errormsg=' . urlencode($msg);
    } else {
      $page = 'error.php';
    }

    return $page;

  }