In this section, I will introduce the header.php file that each page of the project will need to have access the same set of features. This file is actually included by the other files and it includes functions.php file. This means that only a single require_once is needed in each file.
As we see, this file starts by calling the function session_start. This sets up a session that will remember certain values we want to store across different PHP files. With the session started, the program then checks whether the session variable user is currently assigned a value. If so, a user has logged in and the variable $loggedin is set to TRUE.
Using the value of $loggedin, an if block displays one of two sets of menus. The non-logged-in set simply offers options of Home, Sign up, and Log in, whereas the logged-in version offers full access to the project’s features. Additionally, if a user is logged in, his or her username is appended in brackets to the page title and placed after the main heading. We can freely refer to $user wherever we want to put in the name, because if the user is not logged in, that variable is empty and will have no effect on the output.
The styling applied to this file is in the file styles.css and includes creating a wide heading with a colored background, and turning the links in the lists to rounded buttons.
In this section, I helped you build the header.php file included in almost other php files in our project. This file actually defines menus, logo for the site regardless user already logins the site or not.