PEAR应用之AUTH_HTTP


使用AUTH_HTTP,可以方便地构建基于HTTP验证的程序,而且可以自由地指定用户数据表,操作简单易用...
例子:
<?php
require_once("Auth/HTTP.php");
$options = array(
'dsn'=>"mysql://root:@localhost/test", //数据库连接字串
'table'=>"test_http",                  //用户表
'usernamecol'=>"name",            // 用户名字段
'passwordcol'=>"passwd",            //用户密码字段
'cryptType'=>"md5",                // 密码加密码方式
'db_fields'=>"*",                 
);
$a = new Auth_HTTP("DB", $options);

$a->setRealm('yourrealm');            // realm name
$a->setCancelText('Error 401');        // 验证失败时的提示信息
$a->start();                    // starting the authentication process

if($a->getAuth())                // 成功
{
    echo "Hello $a->username welcome to my secret page";
  echo $a->getAuthData('userid');        // 获得其它字段
  echo $a->getAuthData('telephone');      // 
  echo $a->getAuthData('email'); 

 //print_r($a);
};
?>


在要验证的程序前加上此程序即可

本文作者:
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3