60
670
Chapter 29 Building a Web-Based Email Service
Showing the login screen is the default behavior for the application.With no
$action
chosen yet,and no login details supplied, PHP will then execute the following parts of
the code.
In the preprocessing stage,PHP first executes the following code:
include (‘include_fns.php’);
session_start();
These lines start the session that will be used to keep track of the
$auth_user
and
$selected_account
session variables,which we come to later.
As in the other applications, you create short variable names.You have done this in
every form-related script since Chapter 1,“PHP Crash Course,” so it barely needs men-
tion except for the variable
action
.Depending on where in the application this variable
comes from,it might be either a
GET
or
POST
variable.You therefore extract it from the
$_REQUEST
array.You have to do the same thing with the
account
variable because it is
usually accessed via
GET
but is accessed via
POST
when deleting an account.
To save work when customizing the user interface,you use an array to control the
buttons that appear on the toolbar.You declare an empty array as follows:
$buttons = array();
Then you set the buttons that you want on the page:
$buttons[0] = ‘view-mailbox’;
$buttons[1] = ‘new-message’;
$buttons[2] = ‘account-setup’;
If the user later logs in as an administrator, you will add more buttons to this array.
For the header stage, you print a plain vanilla header:
do_html_header($_SESSION[‘auth_user’], “Warm Mail”,
$_SESSION[‘selected_account’]);
...
display_toolbar($buttons);
This code prints the title and header bar and then the toolbar of buttons you can see in
Figure 29.2.These functions are located in the
output_fns.php
function library,but
because you can easily see their effect in the figure,we don’t go through them here.
Next comes the body of the code:
if(!check_auth_user())
{
echo ‘<p>You need to log in</p>’;
if($action&&$action!=’log-out’)
echo ‘ to go to ‘.format_action($action);
echo ‘.<br /><br />’;
display_login_form($action);
}