PHP Browser Persistent Data with PHP Data Persistence on the Web Checking for Sessions

Russell Soppe
Russell Soppe
6,461 Points

How to redirect without header();

I am supposed to redirect to another page. The code I have included works in my local environment but I keep getting a Bummer Error on the exercise indicating that I am not doing a redirect. Any thoughts on how to change the code to clear the exercise?

story.php
<?php
session_start();

if(isset($_SESSION['word'])){
    $word1 = htmlspecialchars($_SESSION['word'][1]);
    $word2 = htmlspecialchars($_SESSION['word'][2]);
    $word3 = htmlspecialchars($_SESSION['word'][3]);
    $word4 = htmlspecialchars($_SESSION['word'][4]);
    $word5 = htmlspecialchars($_SESSION['word'][5]);
}else{
    header('Location: play.php');
    die();
}

include 'inc/header.php';

echo '<h1>My Treehouse Story</h1>';

echo '<p>There once was a(n) ' . $word1;
echo ' programmer named ' . $word2; 
echo '. </p>';
echo '<p>This ' .  $word3; 
echo ' programmer used Treehouse to learn to ' . $word4;
echo ' the ' . $word5 . '.</p>';

echo ' <a class="btn btn-default btn-lg" href="#" role="button">Save Story</a>';
echo ' <a class="btn btn-default btn-lg" href="play.php" role="button">Play Again</a>';
echo ' <a class="btn btn-default btn-lg" href="index.php" role="button">Other Stories</a>';


include 'inc/footer.php';