Heim >Backend-Entwicklung >PHP-Tutorial >基于pear auth实现的登录验证代码

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 09:05:201577Durchsuche
  1. /**
  2. @文件 yz.php
  3. @site http://bbs.it-home.org
  4. */
  5. require_once('Auth.php');
  6. function show_login_form () {
  7. echo '
  8. username:

  9. password:

  10. ' ;
  11. }
  12. $options=array('dsn'=>'mysql://root:1@localhost/zs',
  13. 'table'=>'users',
  14. 'usernamecol'=>'user_name',
  15. 'passwordcol'=>'user_passwd',
  16. 'cryptType'=>'',
  17. 'db_fields'=>'*',
  18. );
  19. $auth=new Auth('DB',$options,'show_login_form');
  20. ?>
  21. $auth->start();
  22. if($auth->checkAuth()){
  23. echo "ok";
  24. echo "
    ";
  25. echo "add";
  26. }else {
  27. echo "error";
  28. }
  29. //$auth->setSessionName($auth->getAuthData('user_name'));
  30. ?>
复制代码

二、yzh.php 传递登录后的session

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


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn