首页 >php教程 >php手册 >基于pear auth实现登录验证

基于pear auth实现登录验证

WBOY
WBOY原创
2016-06-06 20:32:581234浏览

基于pear auth实现登录验证实现代码

建立一个名为yz.php的页面
代码如下:
require_once('Auth.php');
function show_login_form () {
echo '

username:


password:



' ;
}
$options=array('dsn'=>'mysql://root:1@localhost/zs',
'table'=>'users',
'usernamecol'=>'user_name',
'passwordcol'=>'user_passwd',
'cryptType'=>'',
'db_fields'=>'*',
);
$auth=new Auth('DB',$options,'show_login_form');
?>




$auth->start();
if($auth->checkAuth()){
echo "ok";
echo "
";
echo "add";
}else {
echo "error";
}
//$auth->setSessionName($auth->getAuthData('user_name'));
?>



登录后的session传递的页面yzh.php
代码如下:
function back(){
echo 'back';
}
require_once('Auth.php');
$auth=new Auth('DB',$option,'back');
$auth->start();
if($auth->checkAuth())
{
echo "this is a session page,welcome ";
echo "{$auth->getUserName()}";
}
?>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn