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 Build a Simple PHP Application Integrating with PayPal Redirecting Invalid Shirt IDs

ibrahim el shahawy
ibrahim el shahawy
627 Points

i am getting a redirect error

i have checked all the code and it seems to be fine but still outputting a redirect error when the item id in invalid, and displays the page just fine when id is valid.

Cannot modify header information - headers already sent by (output started

Hi Ibrahim,

Can you please post your code? It will help other forum members be able to troubleshoot your issue more effectively. If you need help posting code you can refer to the Markdown Cheatsheet available when posting, essentially you are going to wrap your code in (```) at the beginning and end, without the parenthesis, though.

2 Answers

ibrahim el shahawy
ibrahim el shahawy
627 Points

thank you. here is the code

<?php include("inc/products.php");


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

    if (isset($products["$product_id"])) { 
        $product = $products[$product_id];
       }
} 
if (!isset($product)) {
    header("Location: shirts.php");
    exit();    
}

Where in the document do you have this code placed? Is it at the very top? From the PHP documentation:

"Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file."

ibrahim el shahawy
ibrahim el shahawy
627 Points

it is placed in the very top of the page. i have checked it many times and compared it to the code in the video tutorial but it is still erroring out