02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

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

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

220<br />

CHAPTER 6 ■ PASSWORD PROTECTION SENSITIVE ACTIONS AND AREAS<br />

Creating a Method to <strong>Pro</strong>cess the Logout<br />

To process the logout, a new public method called processLogout() needs to be added to the Admin class.<br />

This method does a quick check to make sure the proper action, user_logout, was supplied, <strong>and</strong> then<br />

uses session_destroy() to remove the user data array <strong>by</strong> destroying the current session entirely.<br />

You add this method to the Admin class <strong>by</strong> inserting the following bold code:<br />

<br />

private $_saltLength = 7;<br />

public function __construct($db=NULL, $saltLength=NULL) {...}<br />

public function processLoginForm() {...}<br />

/**<br />

* Logs out the user<br />

*<br />

* @return mixed TRUE on success or messsage on failure<br />

*/<br />

public function processLogout()<br />

{<br />

/*<br />

* Fails if the proper action was not submitted<br />

*/<br />

if ( $_POST['action']!='user_logout' )<br />

{<br />

return "Invalid action supplied for processLogout.";<br />

}<br />

}<br />

/*<br />

* Removes the user array from the current session<br />

*/<br />

session_destroy();<br />

return TRUE;<br />

private function _getSaltedHash($string, $salt=NULL) {...}

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

Saved successfully!

Ooh no, something went wrong!