基于pear auth实现登录验证

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

1 <?php
2  require_once('Auth.php');
3  function show_login_form () {
4 echo '<form method="post" action="yz.php">
5 <p>username:<input type="text" name="username"></p>
6 <p>password:<input type="password" name="password"></p>
7 <p><input type="submit" value="提交"></p>
8 ' ;
9 }
10
11 $options=array('dsn'=>'mysql://root:1@localhost/zs',
12 'table'=>'users',
13 'usernamecol'=>'user_name',
14 'passwordcol'=>'user_passwd',
15 'cryptType'=>'',
16 'db_fields'=>'*',
17 );
18
19 $auth=new Auth('DB',$options,'show_login_form');
20
21 ?>
22
23 <html>
24 <head>
25 </head>
26 <body>
27 <?php
28 $auth->start();
29 if($auth->checkAuth()){
30 echo "ok";
31 echo "<br>";
32 echo "<a href='yzh.php'>add</a>";
33 }else {
34 echo "error";
35 }
36 //$auth->setSessionName($auth->getAuthData('user_name'));
37 ?>
38 </body>
39 </html>
登录后的session传递的页面yzh.php

1 <?php
2 function back(){
3 echo '<a href="yz.php">back</a>';
4 }
5 require_once('Auth.php');
6 $auth=new Auth('DB',$option,'back');
7 $auth->start();
8 if($auth->checkAuth())
9 {
10 echo "this is a session page,welcome ";
11 echo "{$auth->getUserName()}";
12 }
13 ?>

 

posted @ 2010-02-24 12:18  行走的麦哥  阅读(801)  评论(0编辑  收藏  举报