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


How do I get page to redirect to shirts.php and not Google search for "Redirecting Invalid Shirt IDs" tutorial?

I have entered and reviewed the code that appears to be matching the tutorial.



  if (isset($_GET["id"])) {

    $product_id = $_GET["id"];
    if (isset($products[$product_id])) {

      $product = $products[$product_id];


  if (!isset($products)) {
    header("Location: shirts.php");


  $section = "shirts";
  $pageTitle = $product["name"];


The page works fine showing the shirts. But when I change the id= to an invalid number or remove the id altogether to check the redirect operation I endup at the google search page instead of back at shirts.php like happens for Randy.

EDIT: I did catch that my original post had the exit; command inside the closing curly brace, but there is no change in result.

2 Answers

David Kaneshiro Jr.
David Kaneshiro Jr.
29,247 Points

I think your third if statement should be checking the $product variable not $products.

if (!isset($product)) {
   header ("Location: shirts.php");

I just tried that and the normal page went blank and removing or modifying the id= still goes to google.

Just a thought, I am using XAMPP on Win7 Ult and Firefox31 browser. A test on Chrome 35 came back the same. Could it be a setting in one of these that is causing the google search over a redirect?

I tried it on Chrome35 and the redirect is working but the individual shirt page went blank once I changed the latter isset from $products to $product.

Is there a subject I can check on Caniuse.com to see if there are php issues with redirect or something?

I put exit; back inside the closing curly bracket and the page is now working normally, including redirect in the Chrome browser.

However, the Firefox is still redirecting to a Google search for an unrecognized address, although the shirt page is back up.