Auth_HTTP 例

Auth_HTTP 例 – シンプルなパスワード保護の例

Example

<?php

// Auth_HTTP を使った基本的な実装の例

require_once("Auth/HTTP.php");

// データベース接続オプションの設定
$AuthOptions = array(
'dsn'=>"pgsql://test:test@localhost/testdb",
'table'=>"testable",                            // テーブル名 
'usernamecol'=>"username",            // ユーザ名のコラム
'passwordcol'=>"password",            // パスワードのコラム
'cryptType'=>"none",                // データベース中でのパスワードの暗号化形式
);


$a = new Auth_HTTP("DB"$AuthOptions);

$a->setRealm('yourrealm');            // 領域 (realm) 名
$a->setCancelText('<h2>Error 401</h2>');        // 認証が失敗した際に表示されるメッセージ
$a->start();                    // 認証プロセスの開始


if($a->getAuth())                // 認証すべきユーザかどうかの確認
{
    echo 
"Hello $a->username welcome to my secret page";
    
};

?>