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 Authentication with Session Control<br />

523<br />

Listing 23.5<br />

Continued<br />

echo ‘You are not logged in.’;<br />

echo ‘Only logged in members may see this page.’;<br />

}<br />

echo ‘Back to main page’;<br />

?><br />

This code simply starts a session <strong>and</strong> checks whether the current session contains a registered<br />

user by checking whether the value of $_SESSION[‘valid_user’] is set. If the<br />

user is logged in, you show her the members’ content; otherwise, you tell her that she is<br />

not authorized.<br />

Finally, the logout.php script signs a user out of the system.The code for this script<br />

is shown in Listing 23.6.<br />

Listing 23.6 logout.php—This Script Deregisters the Session Variable <strong>and</strong> Destroys<br />

the Session<br />

<br />

<br />

<br />

Log out<br />

<br />

Back to main page<br />

<br />

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

Saved successfully!

Ooh no, something went wrong!