Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKristofer Doman
18,307 PointsThese poorly designed tests are going to be the end of me
Bummer! When the $_SESSION['word'] array is not set, you should redirect to the play.php page.
Should I Treehouse? Well guess what, I am ..
If I got a dollar of my money back for every time I ran into something that's not functioning properly on this site.
Someone want to tell me what I'm doing wrong?
<?php
session_start();
if (!isset($_SESSION['word'])) {
header('location: play.php');
}
for ($x = 1; $x > 5; $x++) {
if (!isset($_SESSION['word'][$x])) {
header('location: play.php?p=' . $x);
}
}
$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]);
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';
Kristofer Doman
18,307 PointsKristofer Doman
18,307 PointsYes, this works. But it's still not good enough for me.
Is this, or isn't this doing what it's asking me to do in the error?
Tom Gooding
16,735 PointsTom Gooding
16,735 PointsI think because they are asking for you to check each of the session variables, no. Your code just checks for the $_SESSION['word'] variable which would be set - as an array containing the other variables.
Kristofer Doman
18,307 PointsKristofer Doman
18,307 PointsNo, this is the error I got: Bummer! When the $_SESSION['word'] array is not set, you should redirect to the play.php page.
So that's the code I put in.
Tom Gooding
16,735 PointsTom Gooding
16,735 PointsI see what you mean now... and yes, that is confusing.