13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

666 Chapter 29 Building a <strong>Web</strong>-Based Email Service<br />

As you can see, the code calls the login() function, which is similar to the one used in<br />

Chapters 27,“Building User Authentication <strong>and</strong> Personalization,” <strong>and</strong> 28,“Building a<br />

Shopping Cart.” If all goes well, you register the username in the session variable<br />

auth_user.<br />

In addition to setting up the buttons you saw while not logged in, you add another<br />

button to allow the user to log out again, as follows:<br />

if(check_auth_user()) {<br />

$buttons[4] = 'log-out';<br />

}<br />

You can see this Log Out button in Figure 29.3.<br />

In the header stage, you again display the header <strong>and</strong> the buttons. In the body, you<br />

display the status message you set up earlier:<br />

echo $status;<br />

After that, you just need to print the footer <strong>and</strong> wait to see what the user will do next.<br />

Setting Up Accounts<br />

When a user first starts using the Warm Mail system, he will need to set up some email<br />

accounts. If the user clicks on the Account Setup button, this will set the action variable<br />

to account-setup <strong>and</strong> recall the index.php script.The user will then see the output<br />

shown in Figure 29.4.<br />

Figure 29.4<br />

A user needs to set up his email account details<br />

before he can read his email.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!