<?php
    session_start();
?>

<!DOCTYPE html>
<html  xmlns="http://www.w3.org/1999/xhtml">

<!--
    using session attributes to control a little
    multi-page application

    by: Sharon Tuttle
    last modified: 2016-03-23
-->

<head>  
    <title> try-trio </title>
    <meta charset="utf-8" />

    <?php
        require_once("request_name.php");
        require_once("request_quest.php");
        require_once("request_color.php");
        require_once("show_farewell.php");
        require_once("complain_and_exit.php");
    ?>

    <link href="http://users.humboldt.edu/smtuttle/styles/normalize.css" 
          type="text/css" rel="stylesheet" />
</head> 

<body> 

    <h1> try-trio </h1>

    <?php

    if (! array_key_exists('next_page', $_SESSION))
    {
        request_name();
        $_SESSION['next_page'] = "quest";
    }

    elseif ($_SESSION['next_page'] == "quest")
    {
        request_quest();
        $_SESSION['next_page'] = "color";
    }

    elseif ($_SESSION['next_page'] == "color")
    {
        request_color();
        $_SESSION['next_page'] = "farewell";
    }

    elseif ($_SESSION['next_page'] == "farewell")
    {
        show_farewell();
        session_destroy();
    }

    // I HOPE I cannot reach here --- BUT if I
    //     do, I'll destroy the session and restart

    else
    {
        session_destroy();
        session_regenerate_id(TRUE);
        session_start();

        request_name();
        $_SESSION['next_page'] = "quest";
    }

    require_once("328footer-better.html");
?>

</body>
</html>