基于pear auth实现登录验证

建立一个名为yz.php的页面

复制代码 代码如下:


<?php
require_once('Auth.php');
function show_login_form () {
echo '<form method="post" action="https://www.jb51.net/article/yz.php">
<p>username:<input type="text"></p>
<p>password:<input type="password"></p>
<p><input type="submit" value="提交"></p>
' ;
}
$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');
?>
<html>
<head>
</head>
<body>
<?php
$auth->start();
if($auth->checkAuth()){
echo "ok";
echo "<br>";
echo "<a href='https://www.jb51.net/yzh.php'>add</a>";
}else {
echo "error";
}
//$auth->setSessionName($auth->getAuthData('user_name'));
?>
</body>
</html>


登录后的session传递的页面yzh.php

复制代码 代码如下:


<?php
function back(){
echo '<a href="https://www.jb51.net/article/yz.php">back</a>';
}
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()}";
}
?>

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/dd4f811732c0639e037776149d553191.html