コード例 #1
0
//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');
    echo " ";
    echo $authenticate->getAuthData('last_name') . ".<br />";
    $smarty->display('footer.tpl');
}
?>

コード例 #2
0
ファイル: listing14-7.php プロジェクト: alannet/example
<?php

require_once "Auth/HTTP.php";
// Designate authentication credentials, table name,
// username and password columns, password encryption type,
// and query parameters for retrieving other fields
$dblogin = array('dsn' => "mysqli://*****:*****@localhost/chapter14", 'table' => "logins", 'usernamecol' => "username", 'passwordcol' => "pswd", 'cryptType' => "md5", 'db_fields' => "*");
// Instantiate Auth_HTTP
$auth = new Auth_HTTP("MDB2", $dblogin) or die("Can't connect!");
// Message to provide in case of authentication failure
$auth->setCancelText('Authentication credentials not accepted!');
// Begin the authentication process
$auth->start();
// Check for credentials. If not available, prompt for them
if ($auth->getAuth()) {
    echo "Welcome, {$auth->getAuthData('username')}<br />";
}
?>