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 Basic PHP Website (2018) Adding a Basic Form Redirection

Amit Kumar
Amit Kumar
1,063 Points

i am not understanding why it is showing warning and echo "hello world"; please tell me process of this ..

<?php

echo "Hello World!";

header("Location: includelist.php");

1 Answer

Hi there Amit Kumar!

Answer will be pretty simple. You can not send text output before headers. That's why it will show you a warning and doesn't redirect you to another page.

If you want to store the text and show after redirect, you need to use buffer in order to store content between redirects. Or simply add the parameter to the query string inside redirect.

Inside query string.

header("Location: includelist.php?string=Hello%20world");

Inside buffer.

ob_start();
echo "Hello world.";
$result = ob_get_clean();
header("Location: includelist.php");
exit();

Best regards.