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