Auth::Auth()
概要
Auth::Auth (mixed $storageDriver = "DB", mixed $options = "", string $loginFunction = "" [, boolean $showLogin = TRUE])
パラメータ
- string
$storageDriver
使用すべきストレージドライバーの名前、
もしくは独自の Auth_Container オブジェクト
- mixed
$options
ストレージコンテナに渡されるオプション
- string
$loginFunction
ログイン画面を表示するユーザ定義関数の名前
- boolean
$showLogin
ログインがオプションかどうかの定義
注意
この関数は、スタティックにコールする
ことはできません。
例
例 28-1DB パラメータ
<?php
require_once "Auth/Auth.php";
function myOutput($username, $status)
{
... /** See example 1 for the full listing */
}
$params = array(
"dsn" => "mysql://martin:test@localhost/auth",
"table" => "myAuth",
"usernamecol" => "myUserColumn",
"passwordcol" => "myPasswordColumn"
);
$a = new Auth("DB", $params, "myOutput");
$a->start();
if ($a->getAuth()) {
echo "You have been authenticated successfully.";
}
?>
;
|
|
データベーステーブル、
およびカラム名の代替名を指定する方法について示します。
この例では、テーブル myAuth を使用します。
フィールド myUserColumn からユーザー名、
フィールド myPasswordColumn からパスワードを選択します。
デフォルトでは、テーブル名およびフィールド名は
それぞれ、auth および username、password となります。
また、DSN の代わりに、DSN 引数を保持した DB のオブジェクトを
渡すこともできます。
この機能は、
デフォルトと異なるデータベースレイアウトで、
PEAR::Auth を使用したい場合に必要となります。
例
例 28-2独自ストレージコンテナ
<?php
require_once "Auth/Auth.php";
function myOutput($username, $status)
{
... /** See example 1 for the full listing */
}
$a = new Auth(new CustomAuthContainer($options), null, "myOutput");
$a->start();
if ($a->getAuth()) {
echo "You have been authenticated successfully.";
}
?>
|
|
この例は、独自のストレージコンテナを Auth に渡す方法について示しています。
Auth パッケージが提供するストレージコンテナが、
自らの要求に合致しない場合は、独自のストレージコンテナを
作成することができます。
ストレージコンテナの詳細な情報については、
ストレージドライバ
のセクションを参照してください。