Note: Click on the verification code to refresh, use JQ
<script type= "Text/javascript" >$ (document). Ready (function (e) { $ ("#yzm"). Click (function () {$ (this). attr ("src", "__controller__/yzm");}); </script>
2. Back-end verification code generation, operation Method Yzm ()
Generate the Captcha function Yzm () {$config =array ("Footsize" =>15, "IMGW" =>100, "IMGH" =>15, "Length" =>4, "Usezh" = >true,); $Verify =new \think\verify ($config); Reference Verification Code Class Verify$verify->entry (2);//Generate Verification code labeled 2}
3. Login backing operation method: Login ()
function Login () {if (empty ($_post)) {$this->display ();} else{$code =$_post["Yzm"); $verify =new \think\verify (); $z = $verify->check ($code, 2);//Detection Verification code if ($z) {if ($_post["UID "]!=" "&&$_post[" pwd "]!=")//determine if the account and password are empty {$uid =$_post["UID"]; $pwd =$_post["pwd"]; $model =d ("user"); $z =$ Model->field ("pwd")->find ($uid), if ($z ["pwd"]== $pwd) {session ("UID", $uid), $this->success ("Login succeeded", U ("Main /main "));} else{$this->error ("Login Failed", "Login");}} else{$this->error ("User name or password cannot be empty", "Login", 1);}} else{$this->error ("Captcha Error! ");}}}
Second, file upload
1. File Upload Front end: shangchuan.html
<body>
2. Back-end Operation method: Shangchuan ()
Upload form function Shangchuan () {if (empty ($_files)) {$this->display ();} else{$upload =new \think\upload ();//Instantiate upload class $upload->maxsize=3145728;//upload file size $upload->exts=array ("JPG", "gif" , "PNG", "JPEG");//Upload file Format $upload->rootpath= './public/uploads/';//$upload->savapath= ' uploads/'; $upload Savename= ""; $info = $upload->upload ();//var_dump ($info); if ($info) {$this->success ("Upload succeeded");} else{$this->error ($upload->geterror (), "Shangchuan");}}}
Third, obtain the IP address
function IP () {$ip =get_client_ip (); Get the client IP address $ip=new org\net\iplocation ("UTFWry.dat"); Instantiate class, parameter represents IP address library file $area= $IP->getlocation ($IP); Get where an IP address is located}
thinkphp Explanation (11)--Verification code and file upload