1) front-desk login Template:
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTML> <Head> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"> <title>Index</title> <Linkrel= ' stylesheet 'type= ' Text/css 'href= ' __css__/basic.css '/> <Scriptsrc= "__js__/basic.js"></Script> </Head> <Body> <formAction= ' __url__/do_login 'Method= ' Post 'name= ' MyForm '>User name:<inputtype= ' text 'name= ' username '/><BR/>Password:<inputtype= ' Password 'name= ' Password '/><BR/>Verification Code:<inputtype= ' text 'name= ' Code '/> <imgsrc= "__app__/public/code"onclick= ' this.src=this.src+ '? " +math.random () '/> </br/> <imgsrc= ' __public__/images/login.gif 'onclick= "Sub ()"/> </form> </Body></HTML>
2) JS Verification and submit (Basic.js):
function Sub () { var ou=document.myForm.username; var op=Document.myForm.password; var oc=Document.myForm.code; if (ou.value== "| | | op.value==" | | oc.value== ') { alert (' username or password or verification code cannot be null '); } Else { document.myForm.submit (); } }
3) How to generate the CAPTCHA controller:
<? PHP class extends action{ function code () { import (' ORG. Util.image '); Image::buildimageverify (); } }
4) Login-processing controller:
<?PHPclassLoginactionextendsAction {functionindex () {$this-display (); } functionDo_login () {//get the user name and password, and so on. And in the database, there is a user allowed to log on otherwise output error page $username=$_post[' username ']; $password=$_post[' Password ']; $code=$_post[' Code ']; if($_session[' Verify ']!==MD5($code)){ $this->error (' Verification code Error! ‘); } $m=m (' User '); $where[' username ']=$username; $where[' Password ']=$password; $i=$m->where ($where),Count(); if($i>0){ $this->redirect (' User/index '); }Else{ $this->error (' The user does not exist '); } } }
Thinkphp_ Simple Sign-in demo