Emlog实现非插件实现用户注册的方法-站长杂谈下载

Emlog实现非插件实现用户注册的方法

开通本站Svip会员,全站资源免费下
本方法适合于喜欢DIY博客或DIY模板的博主,先在模板中建立一个文件(ps:最好是先复制原模板中的pege.php文件,更改一下文件名就可以了,舍力以zhuce.php为例)
7 @! I  Z, X9 o# S5 G% E; `. I第一步:在新建的zhuce.php中找到<?php echo $log_content; ?>把它替换成如下代码
  1. <?php echo $log_content; ?><table align="center">
    ; Q4 P/ |2 M; r2 m% j
  2. <form action="" method="post" name="reg" id="reg" onsubmit="return checkReg();">9 ^0 R# a8 g& n- s4 I( h( [8 Z0 w/ U
  3. <tr><td align="right">用户名:</td><td><input name="username" class="usr" >* 必填,大于等于5位</td></tr>3 D6 t' L% d9 T1 h$ w4 N3 `- F
  4. <tr><td align="right">密码:</td><td><input name="password" type="password">* 必填,大于等于5位</td></tr>  c. Z' V; B: g! B3 J8 x& m2 X. U; P
  5. <tr><td align="right">重复密码:</td><td><input name="password2" type="password"></td></tr>
    8 J. q7 |* [7 g: a
  6. <tr><td align="right">验证码:</td><td><input name="imgcode" type="text" class="imgcode"><img src="<?php echo BLOG_URL; ?>include/lib/checkcode.php" width="80" id="yzcode" /></td></tr>  z7 Z6 d. B' Y# o& {
  7. <tr><td align="right"></td><td><input type="submit" value="确认注册" class="rbtn"> <input type="reset" value="重置" class="rbtn"></td></tr>, T$ u  _5 g/ f% X7 A" d  }  s
  8. <tr><td><a href="admin/" title="前往登录">已有账号,前往登陆?</a></td></tr>1 w3 D: \* x6 @5 U6 S7 d
  9. </form></table>3 z- T5 b9 m- ^* q: i8 I
  10. <?php' q; {; O# P3 {; I  f# s
  11. session_start();
    / d( N# ?5 }' G2 f" L
  12. !defined('EMLOG_ROOT') && exit('access deined!');
    4 m& r) {7 n3 t. f* V
  13. if(ROLE == 'admin' || ROLE == 'writer'){header('Location:'.BLOG_URL.'admin/');}# Y8 l4 V* k9 u1 K
  14. global $CACHE;
    # D. W1 T+ U5 q1 c
  15. $options_cache = $CACHE->readCache('options');
    9 ~& L9 C( P( G+ ~% h1 I7 n
  16. $DB = MySql::getInstance();
    6 [4 a" ]% U7 G7 ?9 D/ M
  17. $username = isset($_POST['username']) ? addslashes(trim($_POST['username'])) : '';
    : x) N9 s/ B: J7 k9 |  t
  18. $password = isset($_POST['password']) ? addslashes(trim($_POST['password'])) : '';: y5 t8 V1 v( \( Q  C
  19. $password2 = isset($_POST['password2']) ? addslashes(trim($_POST['password2'])) : '';; S# P% l" U' `! m/ v- E
  20. $imgcode = isset($_POST['imgcode']) ? strtoupper(addslashes(trim($_POST['imgcode']))): '';- d5 S9 }; l6 m$ G; Z) f3 K
  21. if($username && $password && $password2 && $imgcode ){
    4 Q1 `0 e# [6 u5 W( X7 o. ~2 i
  22. $sessionCode = isset($_SESSION['code']) ? $_SESSION['code'] : '';! S9 `" b6 E  m) z
  23. //echo $sessionCode;
    2 S. I8 \. \* n1 Z
  24. if($imgcode == $sessionCode){
    # ]1 u7 g# o7 ?. ^/ ^( _* Q! y
  25. $User_Model = new User_Model();
    8 c8 v" c* [- L0 x! h2 q
  26. if(!$User_Model -> isUserExist($username)){
    ) W6 P0 n7 H9 o- [8 F
  27. $hsPWD = new PasswordHash(8, true);
    ( s, J5 C4 e2 _$ e( B
  28. $password = $hsPWD->HashPassword($password);% r# J  n# f7 ~" o3 U
  29. $User_Model->addUser($username, $password, 'writer', 'y');
    # g+ W" @3 ^1 \, i) l+ U  ?
  30. $CACHE->updateCache();
    0 K1 ~6 ^/ |5 g, u1 ~
  31. echo'<script>alert("注册成功!"); window.location.href="'.BLOG_URL.'admin/"</script>';
    2 u7 Q* I( r5 s5 W/ Y4 j
  32. }else{echo'<script>alert("用户名已存在!");</script>';}
    8 i  K" Y1 u8 V4 v5 m) f5 o% M
  33. }else{echo'<script>alert("验证码错误!");</script>';}}
    ; _  _  j, f, Y9 `
  34. ?>
    ; B9 G( f6 c* z/ g
  35. <script type="text/javascript">& t9 ?( n% H% u  b8 C
  36. function checkReg(){, r8 `0 U7 Y6 e# h- y+ \1 \2 C" ]
  37. var usrName = $("input[name=username]").val().replace(/(^\s*)|(\s*$)/g, "");
    8 d& Q9 V* |! X) {5 s
  38. var pwd = $("input[name=password]").val().replace(/(^\s*)|(\s*$)/g, "");* s5 v# N* A) _4 v4 }2 @4 z0 `
  39. var pwd2 = $("input[name=password2]").val().replace(/(^\s*)|(\s*$)/g, "");" g* \' g2 i+ Q9 d1 i2 N  r# p
  40. var yzm = $("input[name=imgcode]").val().replace(/(^\s*)|(\s*$)/g, "");
    : X9 D+ k5 y: O1 q' H
  41. if(usrName.match(/\s/) || pwd.match(/\s/)){alert("用户名和密码中不能有空格");return false;}9 y4 P7 A2 c/ c, |5 L; X
  42. if(usrName == '' || pwd == '' || yzm == ''){alert("用户名、密码、验证码都不能为空!");return false;}
    5 u! B( D! w" `# R8 A3 [) L7 {
  43. if(usrName.length < 5 || pwd.length < 5){alert("用户名和密码都不能小于5位!");return false;}1 H6 D( X3 R6 J. K( f# P" ]
  44. else if(pwd != pwd2){alert("两次输入密码不相等!");return false;}
    + O- n6 B, t- V' J; z
  45. }
    : {! ^4 L: u% q/ e7 Z
  46. $(function(){$("#imginfo").click(function(){
    0 G; T  A) U  l
  47. //alert('haha');
    7 I( N! o  a1 I# P6 a+ e
  48. $("img#yzcode").attr("src", "<?php echo BLOG_URL;?>include/lib/checkcode.php?"+Math.random());
    . K1 d% [# d, G- t
  49. });- W5 l' x& \9 ]) P* q. c9 B- Y
  50. })
    / s2 V- O2 }1 t# }6 D1 a- W5 i
  51. </script>
复制代码
第二步:新建一个页面
9 U& ~# e" O3 x7 n0 W后台-->>页面-->>新建页面-->>填写页面名称(如:用户注册)-->> 修改页面模板为zhuce-->>发布-->>完成。; u% {9 y: q7 t1 D% W0 L& C

# g" y. J/ L1 |0 `* A* \! Y  l
5 G6 f' F% q( v) E7 B! x) D8 U

全部评论 0

您需要登录后才可以回帖 立即登录
登录
0
0
0
返回顶部