Exemplo n.º 1
0
<?php

require_once 'config.php';
require_once 'db_login.php';
require_once 'Auth/HTTP.php';
// We use the same connection string as the pear DB functions
$AuthOptions = array('dsn' => "mysql://{$db_username}:{$db_password}@{$db_host}/{$db_database}", 'table' => "users", 'usernamecol' => "username", 'passwordcol' => "password", 'cryptType' => "md5", 'db_fields' => "*");
//echo "<br/>mysql://$db_username:$db_password@$db_host/$db_database\n<br/>";
$authenticate = new Auth_HTTP("DB", $AuthOptions);
$authenticate->setRealm('Member Area');
$authenticate->setCancelText('<h2>Access Denied</h2>');
// request authentication
$authenticate->start();
// compare username and password to stored values
if ($authenticate->getAuth()) {
    if (!isset($_SESSION)) {
        session_start();
    }
    $smarty->assign('blog_title', $blog_title);
    $smarty->display('header.tpl');
    //setup session variable
    $_SESSION['username'] = $authenticate->username;
    $_SESSION['first_name'] = $authenticate->getAuthData('first_name');
    $_SESSION['last_name'] = $authenticate->getAuthData('last_name');
    $_SESSION['user_id'] = $authenticate->getAuthData('user_id');
    echo $_SESSION['username'];
    echo $_SESSION['first_name'];
    echo $_SESSION['last_name'];
    echo $_SESSION['user_id'];
    echo "Login successful. Great to see you ";
    echo $authenticate->getAuthData('first_name');
<?php

require_once "Auth/HTTP.php";
define('DSN', 'sqlite://dummy:@localhost//tmp/user.db?mode=0644');
$options = array('dsn' => DSN);
$auth = new Auth_HTTP("DB", $options);
$auth->setRealm('dummy', 'sample');
$auth->start();
?>
<html>
<head><title>HTTP Basic authentication test for simple case</title></head>
<body>
<?php 
print "auth: " . $auth->authType . "<br />";
print "username: "******"<br />";
print "password: "******"<br />";
print "auth: " . print_r($auth->auth) . "<br />";
if ($auth->getAuth()) {
    print "authentication is succeeded.<br />";
}
?>
</body></html>