Chinaunix首页 | 论坛 | 博客
  • 博客访问: 17836721
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类:

2008-05-17 18:37:29

使用AUTH_HTTP,可以方便地构建基于HTTP验证的程序,而且可以自由地指定用户数据表,操作简单易用...
例子:
require_once("Auth/HTTP.php");
$options = array(
'dsn'=>"://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);
};
?>


在要验证的程序前加上此程序即可..
阅读(461) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~