Sometimes, you need to setup a structure that checks if a user is logged in. If a user is not logged in, then you should redirect to a login page instead of displaying the rest of the page. There is a very simple way to redirect the page, with the header() function. There are other commands you can send via headers, but for this tutorial we will only show the Location header.
In place of the index.php, you could put absolute paths, relative paths, or completely different domains as the url for redirection. Very easy to do. The only thing you should be aware of by using the header() function is that the page can not start outputting anything otherwise the header() function will throw an error. Say if you started the code with an echo function that displays text, the headers of the webpage would already be sent has text, and you can not edit the headers after they have already been sent.