/**
 * Process errors from the API
 */
function handleErrors($response)
{
    if ($response->hasError()) {
        $statusCode = $response->getResponse()->getStatusCode();
        $message = "HTTP {$statusCode}. Learn more about this error in the <a href=\"https://familysearch.org/developers/docs/guides/http-status-codes\">status codes guide</a>.";
        $details = '';
        $type = 'danger';
        // 401 - Unauthenticated
        if ($response->hasStatus(401)) {
            $type = 'warning';
            if (isset($_SESSION['fs_access_token'])) {
                $details = 'Your session has expired. <a href="/examples/OAuth2Code.php">Sign in</a> again.';
            } else {
                $details = '<a href="/examples/OAuth2Code.php">Sign in</a> to use the sample app.';
            }
        }
        if ($details) {
            $message .= '<br><br>' . $details;
        }
        printStatusMessage($message, $type);
    }
}
<?php

include '../header.php';
// If the request for the authorization code resulted in an error then display the message.
if (isset($_GET['error'])) {
    $message = '<p class="lead">There was an error while authenticating.</p>
        <p>Error type: ' . $_GET['error'] . '></p>
        <p>Error description: ' . $_GET['error_description'] . '></p>';
    printStatusMessage($message, 'danger');
} else {
    if (isset($_GET['code'])) {
        // Get the code from the URL params
        $code = $_GET['code'];
        // Exchange the code for an access token
        $token = $client->authenticateViaOAuth2AuthCode($code)->getAccessToken();
        // Store the access token in a session variable
        $_SESSION['fs_access_token'] = $token;
        ?>
      <h2>Access Token</h2>
      <p>Here's the access token we obtained. It has been stored in a
      session so that future interactions in the sample app are authenticated.</p>
      <pre><?php 
        echo $token;
        ?>
</pre>
    <?php 
        // Get and store the user's information so that we can show
        // the sign-in status in the header
        $response = $client->familytree()->readCurrentUser();
        // Check for errors
        if ($response->hasError()) {