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

Jiri Stepanek
Jiri Stepanek
10,740 Points

Moving through pages

Hi, how can you move to a different page in PHP? Like in HTML you have to do <a href="hello.html">HI</a> and click to it. I wanna do the same but without that click. If it's possible, with no framework. TY ;)

2 Answers

Jeff Lemay
Jeff Lemay
14,268 Points

You can use php's header function.

<?php
header('Location: /example/path/here.php');
exit;
?>
Jeff Lemay
Jeff Lemay
14,268 Points

Documentation

The biggest struggle I had with this in the past was, you cannot have anything output to the page before you call this function. So if you have a space or empty line at the top of your document before you open your php tag and call the header function, the function will fail.

Jiri Stepanek
Jiri Stepanek
10,740 Points

thanks Jeff, that works ;)