《PHP應(yīng)用:PHP+jQuery 注冊(cè)模塊的改進(jìn)(三):更新到Smarty3.1》要點(diǎn):
本文介紹了PHP應(yīng)用:PHP+jQuery 注冊(cè)模塊的改進(jìn)(三):更新到Smarty3.1,希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
PHP學(xué)習(xí)Smarty3.1X( 最新版本 3.1.19) 比起Smarty2.x修改了不少特性.我把這個(gè)模塊使用Smarty3.1.18 ( 下載地址http://www.smarty.net/files/Smarty-3.1.18.zip )重新修改了一遍,是項(xiàng)目文件和目錄看起來(lái)更干凈更有療養(yǎng).
PHP學(xué)習(xí)把Smarty壓縮包中的libs文件夾拷貝至模塊根目錄下,然后根目錄創(chuàng)立init.inc.php:
PHP學(xué)習(xí)/* *********************Smarty設(shè)置*********************** */
//根目錄路徑方式,用于Smarty設(shè)置
define("ROOT",str_replace("\\","/",dirname(__FILE__))."/");
PHP進(jìn)修require ROOT.'libs/Smarty.class.php';
$smarty = new Smarty();
PHP進(jìn)修//Smarty3設(shè)置默認(rèn)路徑
$smarty ->setTemplateDir(ROOT.'templates/')
??????? ->setCompileDir(ROOT.'templates_c/')
??????? ->setPluginsDir(ROOT.'plugins/')
??????? ->setCacheDir(ROOT.'cache/')
??????? ->setConfigDir(ROOT.'configs');
PHP學(xué)習(xí)$smarty->caching = false;
$smarty->cache_lifetime = 60*60*24; //模版緩存有效光陰為1天
$smarty->left_delimiter = '<{';
$smarty->right_delimiter = '}>';
PHP進(jìn)修/***********************************************************/
PHP學(xué)習(xí)//根目次url方式
$PHP_SELF=$_SERVER['PHP_SELF'];
$ROOT_URL='http://'.$_SERVER['HTTP_HOST'].substr($PHP_SELF,0,strrpos($PHP_SELF,'/')+1);
define(ROOT_URL,$ROOT_URL);
PHP學(xué)習(xí)//模版目次url方式
define("Template_Dir",$ROOT_URL.'templates');
PHP學(xué)習(xí)創(chuàng)建初始化文件中呈現(xiàn)的templates,templates_c,plugins,cache,configs文件夾.
PHP學(xué)習(xí)修改的文件都比擬相似,而且也非常easy,這里列出register.html和register.php文件的修改.
PHP進(jìn)修register.html是注冊(cè)的前臺(tái)頁(yè)面,路徑是/templates/register.html
PHP學(xué)習(xí)<script src="<{$Template_Dir}>/js/jquery-1.8.3.min.js"></script>
<script src="<{$Template_Dir}>/js/register.js"></script>
<!--郵箱下拉-->
<script src="<{$Template_Dir}>/js/emailup.js"></script>
</head>
PHP進(jìn)修<body>
<{*導(dǎo)入header.html*}>
<{include file="header.html"}>
PHP進(jìn)修<!-- 內(nèi)容區(qū) -->
<div id="container">
PHP進(jìn)修??? <!--注冊(cè)區(qū)-->
??? <div id="register">
PHP學(xué)習(xí)??????? <!-- 注冊(cè)表單 -->
??????? <form id="register-form" action="register_chk.php" method="post">
???????????
??????????? <!-- 用戶名 -->???????
??????????? <!-- placeholder HTML5的屬性,提供提示信息.輸入字段為空時(shí)顯示,并會(huì)在字段獲得焦點(diǎn)時(shí)消失 -->
??????????? <div class="ipt fipt">
??????????????? <input type="text" name="uname" id="uname" value="" placeholder="輸入用戶名"? autocomplete="off" />
??????????????? <!--提示筆墨-->
??????????????? <span id="unamechk"></span>
??????????? </div>
PHP進(jìn)修??????????? <!-- email -->???????????
??????????? <div class="ipt">
??????????????? <input type="text" name="uemail" id="uemail" value="" placeholder="常用郵箱地址" autocomplete="off" /><span id="uemailchk"></span><ul class="autoul"></ul>
??????????? </div>
PHP學(xué)習(xí)??????????? <!-- 暗碼 -->
??????????? <div class="ipt">
??????????????? <input type="password" name="upwd" id="upwd" value="" placeholder="設(shè)置暗碼" /><div class="upwdpic"><span id="upwdchk"></span><img id="pictie" /></div>
??????????? </div>
???????????
??????????? <!-- 重復(fù)暗碼 -->
??????????? <div class="ipt">
??????????????? <input type="password" name="rupwd" id="rupwd" value="" placeholder="確認(rèn)暗碼" /><span id="rupwdchk"></span>
??????????? </div>
PHP進(jìn)修??????????? <!--驗(yàn)證碼-->
??????????? <div class="ipt iptend">
??????????????? <input type='text' id='yzm' name='yzm' placeholder="驗(yàn)證碼" autocomplete="off" />
??????????????? <img id='yzmpic' src='valcode.php?num=<{showval}>' style="cursor:pointer" alt="驗(yàn)證碼" title="驗(yàn)證碼">
??????????????? <a style="cursor:pointer" id='changea'>
??????????????????? <img id="refpic" src="<{$Template_Dir}>/images/ref.jpg" alt="刷新驗(yàn)證碼">
??????????????? </a>
??????????????? <span id='yzmchk'></span>
??????????? </div>
PHP學(xué)習(xí)??????????? <!-- 提交 -->
??????????? <button type="button" id="sub">立刻注冊(cè)</button>
PHP學(xué)習(xí)??????????? <!-- 服務(wù)條款 -->
??????????? <span class="fuwu">
??????????????? <input type="checkbox" name="agree" id="agree" checked="checked">
??????????????? <label for="agree">我同意? <a href="#">" 服務(wù)條款? "</a> 和? <a href="#">" 網(wǎng)絡(luò)游戲用戶隱私權(quán)掩護(hù)和個(gè)人信息利用政策 "</a>
??????????????? </label>
??????????? </span>
PHP進(jìn)修??????? </form>
PHP進(jìn)修??? </div>
PHP進(jìn)修</div>
</body>
</html>
PHP進(jìn)修register.php:
PHP進(jìn)修session_start();
PHP進(jìn)修require_once 'init.inc.php';
PHP學(xué)習(xí)//設(shè)置模版目次,用于模版頁(yè)頭部引用CSS、JS、Images
$smarty->assign("Template_Dir",Template_Dir);
PHP進(jìn)修$smarty->display('register.html');
PHP學(xué)習(xí)同時(shí)擴(kuò)充了天生驗(yàn)證碼插件,路徑是/plugins/function.showval.php
PHP學(xué)習(xí)//天生驗(yàn)證碼
function smarty_function_showval($params,$smarty){
PHP進(jìn)修??? $num = "";
??? for($i=0;$i<4;$i++){
PHP進(jìn)修??????? $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;
??????? }???
??? }
PHP進(jìn)修??? $mdnum = md5($num);
??? $_SESSION['num'] = $num;
??? $_SESSION['mdnum'] = $mdnum;
PHP進(jìn)修??? //寫在session之后
??? return $mdnum;
}
PHP進(jìn)修$_SESSION['num'] = smarty_function_showval($params,$smarty);
$_SESSION['mdnum'] = md5(smarty_function_showval($params,$smarty));
PHP學(xué)習(xí)注意插件的定名:
PHP學(xué)習(xí)文件名要放在根目錄的plugins目錄下,命名規(guī)則是 function.函數(shù)名.php,文件中函數(shù)的命名規(guī)則是 smarty_function_函數(shù)名($params,$smarty),此中第一個(gè)參數(shù)是傳遞給模板的關(guān)聯(lián)數(shù)組,第二個(gè)參數(shù)是接收自動(dòng)傳入的smarty對(duì)象,函數(shù)要有返回值.
PHP進(jìn)修更多代碼見(jiàn):https://github.com/dee0912/myGit
歡迎參與《PHP應(yīng)用:PHP+jQuery 注冊(cè)模塊的改進(jìn)(三):更新到Smarty3.1》討論,分享您的想法,維易PHP學(xué)院為您提供專業(yè)教程。
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/14553.html