进入 PHPChina 首页
当前位置:PHPChina 开源社区门户 - PHP编程技巧 - 正文
[字号:  ]

PEAR应用之AUTH_HTTP

发布时间:2008-4-02 17:25   作者: 网络转载   信息来源: www.83year.net  [我来说两句(1101条)]
使用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);
};
?>


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

字号:   | 推荐给好友

[我来说两句(1101条)]
现在有0人对本文发表评论 查看全部评论>>评论区

 

评分:0

验证码: seccode