Learning PHP and MySQL
Monday, September 25, 2006
Example 13-19 Using Auth_HTTP to authenticate a user
<?php
// Using Auth_HTTP to limit access require_once('db_login.php'); require_once("Auth/HTTP.php");
// We use the same connection string as the pear DB functions
$AuthOpts = array(
'dsn' => "mysql://$db_username:$db_password@$db_host/$db_database",
'table' => "users", // your table name
'usernamecol' => "username", // the table username column
'passwordcol' => "password", // the table password column
'cryptType' => "md5", // password encryption type
);
$authenticate = new Auth_HTTP("DB", $AuthOpts);
// Set the realm name
$authenticate->setRealm('Member Area');
// Authentication failed error message
$authenticate->setCancelText('<h2>Access Denied</h2>');
// Request authentication
$authenticate->start();
// compare username and password to stored values if ($authenticate->getAuth()){
echo "Welcome back to our site ".$authenticate->username.".";
}
?>
Posted by krautgrrl on 09/25 at 11:48 AM
Chapter 13 Code • (27) Comments • (1) Trackbacks • Permalink
Chapter 13 Code • (27) Comments • (1) Trackbacks • Permalink
Statistics
This page has been viewed 407345 times
Page rendered in 0.3216 seconds
Total Entries: 224
Total Comments: 16
Total Trackbacks: 307338
Most Recent Entry: 09/27/2006 12:39 pm
Most Recent Comment on: 10/26/2007 10:00 am
Total Members: 2
Total Logged in members: 0
Total guests: 12
Total anonymous users: 0
Most Recent Visitor on: 05/19/2012 06:23 am
The most visitors ever was 1103 on 11/20/2007 12:50 pm
