<?php namespace Home\Controller; use Think\Controller; use Home\Model\loginModel; class TestController extends Controller { public function Add () { /*$login=D("login");*/ $login=new loginModel(); //var_dump($login); //var_dump($login->select()); if(empty($_POST)) { $this->display(); } else { $z= $login->create(); //var_dump ($z); if($z) { echo "This Is Ok"; //$login->add(); } else { $str=$login->getError(); $this->assign("error",$str); $this->display(); } } } public function YZM() { $config=array( 'useImgBg' => true, // 使用背景圖片 'fontSize' => 25, // 驗證碼字體大小(px) 'useCurve' => true, // 是否畫混淆曲線 'useNoise' => true, // 是否添加雜點 'imageH' => 0, // 驗證碼圖片高度 'imageW' => 0, // 驗證碼圖片寬度 'length' => 5, // 驗證碼位數 'useZh' => true, 'fontttf' => 'STKAITI.TTF', // 驗證碼字體,不設置隨機獲取 'bg' => array(243, 251, 254), // 背景顏色 'reset' => true, // 驗證成功後是否重置 ); $v=new\Think\Verify($config); $v->entry(); } public function Denglu() { if(empty($_POST)) { $this->display(); } else { $v=new\Think\Verify(); $z=$v->check($_POST["YZM"]); var_dump($z); } } }
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文檔</title> <script src="../../../../../jq.js"></script>//引入路徑必定要注意,最好是絕對路徑 </head> <body> <form action="__SELF__" method="post" > <div>用戶名:<input type="text" name="UserName" /></div> <div>密碼:<input type="text" name="Password" /></div> <div>驗證碼:<img id="yzm" src="__CONTROLLER__/YZM" /><input type="text" name="YZM" /></div> <div><input type="submit" value="登陸" /></div> </form> </body> </html> <script type="text/javascript"> $(document).ready(function(e) { $("#yzm").click(function(){ var str = "a/"+Math.random();//火狐瀏覽器不加隨機數有緩存 $(this).attr("src","__CONTROLLER__/YZM/"+str); } ) }); </script>