PHP+jQuery 注册模块的改进(三):更新到Smarty3.(2)

<!--验证码-->
            <div>
                <input type='text' placeholder="验证码" autocomplete="off" />
                <img src='valcode.php?num=<{showval}>' alt="验证码" title="验证码">
                <a>
                    <img src="https://www.jb51.net/<{$Template_Dir}>/images/ref.jpg" alt="刷新验证码">
                </a>
                <span></span>
            </div>

<!-- 提交 -->
            <button type="button">立即注册</button>

<!-- 服务条款 -->
            <span>
                <input type="checkbox" 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));

注意插件的命名:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/379e16ab51b67983e70a8cf32144c89e.html