11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

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

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

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

CHAPTER 14• AUTHENTICATING YOUR USERSwww.it-ebooks.infoAuthenticating Against a <strong>MySQL</strong> DatabaseBecause Auth_HTTP subclasses the Auth package, it inherits all of Auth‘s capabilities. Because Authsubclasses the DB package, Auth_HTTP can take advantage of this popular database abstraction layer tostore authentication information in a database table. To store the information, this example uses a tableidentical to one used earlier in this chapter:CREATE TABLE logins (id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,username VARCHAR(255) NOT NULL,pswd CHAR(32) NOT NULL);Next, you need to create a script that invokes Auth_HTTP, telling it to refer to a <strong>MySQL</strong> database. Thisscript is presented in Listing 14-7.Listing 14-7. Validating User Credentials with Auth_HTTP// Check for credentials. If not available, prompt for themif($auth->getAuth())echo "Welcome, {$auth->getAuthData('username')}";312

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

Saved successfully!

Ooh no, something went wrong!