<?php class LoginAction extends Action { function index(){ $this->display(); } function do_login(){ //獲取用戶名和密碼信息,和數據庫中比對 // echo 111111111; // dump($_POST); // dump($_SESSION); $username=$_POST['username']; $password=$_POST['password']; $code=$_POST['code']; if($_SESSION['verify']!==md5($code)) { $this->error('驗證碼錯誤'); } /* else {$this->show('登陸成功');} */ $m=new Model('user'); $where['username']=$username; //$where['password']=$password; $i=$m->where($where)->count(); if ($i>0){$this->redirect('User/index');} else{$this->error('該用戶不存在');}; } } ?> ///調用Login/index Login模塊的index方法,登錄頁面內容: <!-- form 表單 table 表格 td 單元格 tr 行標籤 --> <!doctype html> <html lang="en"> <head> <meta name="Generator" content="EditPlus?"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>Document</title> <link rel='stylesheet' type='text/css' href='__PUBLIC__/Css/login.css'/> <link rel='stylesheet' type='text/css' href='__PUBLIC__/Css/basic.css'/> <script src="__PUBLIC__/Js/login.js"></script> </head> <body> <!doctype html> <html lang="en"> <head> <meta name="Generator" content="EditPlus?"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>Document</title> </head> <body> <center> <h1>中均運維管理平臺</h1> <!--圖片標籤--> <img class="img_bk" src="__PUBLIC__/Images/scan.jpg"/> </center> <!--表單提交--> <form action='__URL__/do_login' method='post' name="myForm"> <center> <table cellspacing="0" cellpadding="0"> <tr> <td class="td1">用戶名:</td> <td><input type="text" name="username"/></td> <td class="td3"></td> <tr/> <tr> <td class="td1">密碼:</td> <td><input type="password" name="password"/></td> <td class="td3"></td> <tr/> <tr> <td class="td1">驗證碼:</td> <td> <input type='text' name='code' /></td> <td class="td3"><img src="__APP__/Public/code" onclick='this.src=this.src+"?"+Math.random()'/></td> </tr> <center> <tr> <td class="td1"></td> <!-- <td align="center" ><input type="submit" name="login" value="login" /></td> --> <td> <img src="__PUBLIC__/Images/login.jpg" onclick="login()"/> </td> <td class="td3"></td> </tr> <center/> <center/> </form> </body> </html> </body> </html> //__PUBLIC__/Js/login.js 調用的js來自,利用的login方法 <script src="/thinkphp/Public/Js/login.js"></script> function login() { var ou=document.myForm.username; var op=document.myForm.password; var oc=document.myForm.code; if (ou.value==''||op.value==''||oc.value==''){ alert ('用戶名,密碼或者驗證碼不能爲空'); }else{ document.myForm.submit(); } } POST 請求調用的方法: __URL__/do_login <!--表單提交--> <form action='/thinkphp/index.php/Login/do_login' method='post' name="myForm">