Home > php教程 > php手册 > PEAR应用之AUTH_HTTP

PEAR应用之AUTH_HTTP

WBOY
Release: 2016-06-13 10:35:45
Original
1758 people have browsed it

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


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

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template