13.09.2016 Views

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Implementing Administrative Functions<br />

721<br />

Listing 30.13 Continued<br />

echo "Your old password is incorrect.";<br />

}<br />

}<br />

return false; // old password was wrong<br />

This function is similar to other password setting <strong>and</strong> changing functions we have looked<br />

at. It compares the two new passwords entered by the user to make sure they are the<br />

same <strong>and</strong>, if they are, tries to update the user’s password in the database.<br />

Logging Out<br />

When a user clicks on the Log Out button, the log-out action is triggered.The code<br />

executed by this action in the main script is actually in the preprocessing section of the<br />

script, as follows:<br />

if($action == 'log-out') {<br />

unset($action);<br />

$_SESSION=array();<br />

session_destroy();<br />

}<br />

This snippet of code disposes of the session variables <strong>and</strong> destroys the session. Notice that<br />

it also unsets the action variable; this means that you enter the main case statement<br />

without an action, triggering the following code:<br />

default:<br />

if(!check_logged_in()) {<br />

display_login_form($action);<br />

}<br />

break;<br />

This code allows another user to log in or allows the user to log in as someone else.<br />

Implementing Administrative Functions<br />

If someone logs in as an administrator, she will get some additional menu options, which<br />

can be seen in Figure 30.10.<br />

The extra options are Create List (create a new mailing list), Create Mail (create a<br />

new newsletter), <strong>and</strong> View Mail (view <strong>and</strong> send created newsletters that have not yet<br />

been sent). Now let’s look at each of these options in turn.

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

Saved successfully!

Ooh no, something went wrong!