11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

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

www.it-ebooks.infoCHAPTER 14 • AUTHENTICATING YOUR USERS}if ($stmt->num_rows == 0)authenticate_user();?>Although database authentication is more powerful than the previous two methodologiesdescribed, it is really quite trivial to implement. Simply execute a selection query against the loginstable, using the entered username and password as criteria for the query. Of course, such a solution isnot dependent upon specific use of a <strong>MySQL</strong> database; any relational database could be used in itsplace.Taking Advantage of PEAR: Auth_HTTPWhile the approaches to authentication discussed thus far work just fine, it’s always nice to hide some ofthe implementation details within a class. The PEAR class Auth_HTTP satisfies this desire quite nicely,taking advantage of Apache’s authentication mechanism and prompt (see Figure 14-1) to produce anidentical prompt but using <strong>PHP</strong> to manage the authentication information. Auth_HTTP encapsulatesmany of the messy aspects of user authentication, exposing the information and features you’re lookingfor by way of a convenient interface. Furthermore, because it inherits from the Auth class, Auth_HTTP alsooffers a broad range of authentication storage mechanisms, some of which include the DB databaseabstraction package, LDAP, POP3, IMAP, RADIUS, and SAMBA. This section shows you how to takeadvantage of Auth_HTTP to store user authentication information in a flat file.Installing Auth_HTTPTo take advantage of Auth_HTTP‘s features, you need to install it. Therefore, invoke PEAR and pass it thefollowing arguments:%>pear install -o auth_httpBecause Auth_HTTP is dependent upon another package (Auth), you should pass at least the -ooption, which will install this required package. Execute this command and you’ll see output similar tothe following:downloading Auth_HTTP-2.1.6.tgz ...Starting to download Auth_HTTP-2.1.6.tgz (9,327 bytes).....done: 9,327 bytesinstall ok: channel://pear.php.<strong>net</strong>/Auth_HTTP-2.1.6Once installed, you can begin taking advantage of Auth_HTTP‘s capabilities. For purposes ofdemonstration, the following section considers how to authenticate against the database.311

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

Saved successfully!

Ooh no, something went wrong!