For uniformity, each page of the project needs to have the same overall design and layout. Therefore I placed these things in Example 20-2, rnheader.php. This is the file that is actually included by the other files and it, in turn, includes rnfunctions.php. This means that only a single include is required in each file.

rnheader.php starts by calling the function session_start. As you’ll recall from Chapter 13, this sets up a session that will remember certain values we want stored 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 nonlogged-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 before the menu options. 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 only styling applied in this file is to set the default font to Verdana at a size of 2 via a <font...> tag. For a more comprehensive design and layout, you’ll probably wish to apply CSS styling to the HTML.

Example 20-2. rnheader.php
<?php // rnheader.php include ...

Get Learning PHP, MySQL, and JavaScript now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.