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 Introduction to User Authentication in PHP Setting Up Authorization Creating Helper Functions

What is the difference between `header()` and `redirect()`

What is the difference between header() and redirect() in PHP? I can not find any information about this redirect() function.

2 Answers

Alena Holligan
STAFF
Alena Holligan
Treehouse Teacher

redirect is a custom function while header is a built-in function. Setting up our own redirect allows us to add more options to the redirect. We could use the built-in header function or, the Symfony\HttpFoundation package. We could control status codes and 'exit' to make sure no other code on that page attempts to run after the redirect.

Pascal Boschma
Pascal Boschma
379 Points

redirect() isn't a PHP function. You can redirect with header() though. However, you could make a function with that name yourself.

header("Location: http://www.example.com/");