首页 > 学院 > 开发设计 > 正文

PEAR应用之AUTH_HTTP

2019-11-17 04:22:21
字体:
来源:转载
供稿:网友

使用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);
};
?>


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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表