<?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>
示例#2
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');
示例#3
0
<?php

require_once "mysql.php";
require_once "Auth/HTTP.php";
// setting the database connection options
$AuthOptions = array('dsn' => "mysql://{$sql_user}:{$sql_pass}@{$sql_host}/{$sql_data}", 'table' => "auth", 'usernamecol' => "username", 'passwordcol' => "password", 'cryptType' => "none", 'db_fields' => "*");
$auth_http = new Auth_HTTP("DB", $AuthOptions);
$auth_http->setRealm('admin4am');
// realm name
$auth_http->setCancelText('<h2>Error 401 - no login!</h2>');
// error message if authentication fails
$auth_http->start();
// starting the authentication process