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 trial

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

Johannes Chitura
seal-mask
.a{fill-rule:evenodd;}techdegree
Johannes Chitura
PHP Development Techdegree Student 8,907 Points

I am having a difficult time grasping what this question is asking?

I seem not to understand what the question is asking and as a result, I am unable to solve this problem. Would someone please try to breakdown what is being asked?

story.php
<?php
session_start();
$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';

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Johannes Chitura ! Let's see if I can phrase this a bit differently. We have a $_SESSION variable that has the key "word". At that key there is an array starting with index 1 and extending to 5. If any one of those is empty we want to redirect to play.php and provide it a query string with the one that is missing.

For instance, if $_SESSION['word'][2] is empty, I would expect it to go to this URL: play.php?p=2. Note that it says to set the p parameter equal to the first missing session variable. I might suggest a for loop starting with 1 and running up to and including 5 :smiley:

Hope this helps! :sparkles: