PHP+jQuery 注册模块的改进(三):更新到Smarty3.1(2)
<!-- 密码 -->
<div class="ipt">
<input type="password" name="upwd" id="upwd" value="" placeholder="设置密码" /><div class="upwdpic"><span id="upwdchk"></span><img id="pictie" /></div>
</div>
<!-- 重复密码 -->
<div class="ipt">
<input type="password" name="rupwd" id="rupwd" value="" placeholder="确认密码" /><span id="rupwdchk"></span>
</div>
<!--验证码-->
<div class="ipt iptend">
<input type='text' id='yzm' name='yzm' placeholder="验证码" autocomplete="off" />
<img id='yzmpic' src='valcode.php?num=<{showval}>' style="cursor:pointer" alt="验证码" title="验证码">
<a style="cursor:pointer" id='changea'>
<img id="refpic" src="<{$Template_Dir}>/images/ref.jpg" alt="刷新验证码">
</a>
<span id='yzmchk'></span>
</div>
<!-- 提交 -->
<button type="button" id="sub">立即注册</button>
<!-- 服务条款 -->
<span class="fuwu">
<input type="checkbox" name="agree" id="agree" checked="checked">
<label for="agree">我同意 <a href="#">" 服务条款 "</a> 和 <a href="#">" 网络游戏用户隐私权保护和个人信息利用政策 "</a>
</label>
</span>
</form>
</div>
</div>
</body>
</html>
register.php:
<?php
session_start();
require_once 'init.inc.php';
//设置模版目录,用于模版页头部引用CSS、JS、Images
$smarty->assign("Template_Dir",Template_Dir);
$smarty->display('register.html');
同时扩充了生成验证码插件,路径是/plugins/function.showval.php
<?php
//生成验证码
function smarty_function_showval($params,$smarty){
$num = "";
for($i=0;$i<4;$i++){
$tmp = rand(1,15);
if ($tmp > 9) {
switch ($tmp) {
case(10):
$num .= 'a';
break;
case(11):
$num .= 'b';
break;
case(12):
$num .= 'c';
break;
case(13):
$num .= 'd';
break;
case(14):
$num .= 'e';
break;
case(15):
$num .= 'f';
break;
}
} else {
$num .= $tmp;
}
}
$mdnum = md5($num);
$_SESSION['num'] = $num;
$_SESSION['mdnum'] = $mdnum;
//写在session之后
return $mdnum;
}
$_SESSION['num'] = smarty_function_showval($params,$smarty);
$_SESSION['mdnum'] = md5(smarty_function_showval($params,$smarty));
注意插件的命名:






