Thinkphp Verification Code and pagination Instance Tutorial _php instance

Source: Internet
Author: User

This article illustrates the two common features of thinkphp: Authenticode and pagination. It is very common in the project development of thinkphp and has high practical value. Complete examples to share with you for your reference. Specifically as follows:

First, the Verification code:

Import authentication code class, there is a verification code method in the Aoli\thinkphp\lib\org\util\image.class.php

1. English Verification Code:

Buildimageverify ($length, $mode, $type, $width, $height, $verifyName)

The parameters are as follows:

Length: The size of the verification code, which defaults to 4 digits
Mode: Verifies the type of string, defaults to number, other support type has 0 letters 1 digits 2 Capital Letter 3 Small Letter 4
Chinese 5 blend (remove easily confusing characters Ooll and number 01)
Type: The picture type of the CAPTCHA, which defaults to PNG
Width: Verify the size of the code, the default will automatically based on the length of the verification code automatically calculated
Height: Verify code Heights, defaults to 22
VerifyName: The name of the session record for the validation code, which defaults to verify

2. Chinese Verification Code:

Gbverify ($length, $type, $width, $height, $fontface, $verifyName)

The parameters are as follows:

Length: The size of the verification code, which defaults to 4 digits
Type: The picture type of the CAPTCHA, which defaults to PNG
Width: Verify the size of the code, the default will automatically based on the length of the verification code automatically calculated
Height: Verify code Heights, defaults to 50
Fontface: The font file used, using the full file name or under the directory where the image class is located, the default font file used is Simhei.ttf (the file can be found from the window's Fonts directory)
VerifyName: The name of the session record for the validation code, which defaults to verify

3. If the verification code cannot be displayed, please check:

Whether the ①.php has installed the GD library support;
②. Whether there is any output prior to the output (especially the UTF8 BOM header information output);
③.image class library is properly imported;
④. If the Chinese verification code checks whether there is a copy font file to the class library directory;

4.action section:

The CommonAction.class.php page code is as follows:

<?php
class Commonaction extends action{
  function verify () {    
    import (' ORG. Util.image ');
    English Verification Code
    //image::buildimageverify (5,5,gif,90,30, ' verify ');
    Chinese Verification Code
    image::gbverify ();
  }
? >

5.view Template section:

The template Index.html page is as follows:

 Verify code: <input type= "Text" name= "verify"/><BR/ >
 <input type= "Submit" value= "registered"/>
</form>

<script type= "Text/javascript" >
  function Show (obj) {
    obj.src= "__app__/common/verify/random/" +math.random ();    
  }
</script>

6. Controller:

Controller UserAction.class.php as follows:

Verification Code Verification
if ($_session[' verify ']!=md5 ($_post[' verify ')) {
  $this->error (' Authenticode incorrect ');   
}

Second, pagination:

1. Import the pagination class, in the aoli\thinkphp\lib\org\util\page.class.php has the authentication code method

2.action section:

The UserAction.class.php page is as follows:

function index () {
  import (' ORG. Util.page ');//Introducing the distribution class
  $user =m (' user ');
  $count = $user->count ();
  $page =new page ($count, 3);//page shows 5
  $page->setconfig (' theme ', ' <div style= ' font-weight:bold;] > Total:%totalrow%%header%%nowpage%/%totalpage%%first%%uppage%%prepage%%linkpage%%nextpage%%downPage%%end%< /div> ');
  $show = $page->show ();
  $list = $user->field (array (' ID ', ' username ', ' createip '))->order (' id desc ')->limit ($page->firstrow. '). $page->listrows)->select ();
  $this->assign (' alist ', $list);
  $this->assign (' page ', $show);
  $this->display ();
}

3.view Template section:

Template page index.html page is as follows:

<volist name= "alist" id= "Vo" >
 <li><span>id:</span>{$vo [' ID ']}<span> username: </ span>{$vo [' username ']}<span> registered ip:</span>{$vo [' Createip ']}<a href= ' __url__/del/id/{$vo [' id ']} ' > Delete </a> <a href= "__url__/edit/id/{$vo [' ID ']}" > Edit </a></li>
</volist>
{$ Page

Interested readers can debug and run this article thinkphp verification code and pagination examples, I believe there will be a new harvest.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.