search
HomeBackend DevelopmentPHP TutorialThinkPHP verification code and paging example tutorial, thinkphp example tutorial_PHP tutorial

ThinkPHP verification code and paging example tutorial, thinkphp example tutorial

The examples in this article describe two commonly used functions of ThinkPHP: verification code and paging. It is very common in ThinkPHP project development and has high practical value. The complete example is shared with everyone for your reference. The details are as follows:

1. Verification code:

Import the verification code class, there is a verification code method in aoliThinkPHPLibORGUtilImage.class.php

1. English verification code:

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

The parameters are as follows:

length: The length of the verification code, the default is 4 digits
mode: The type of verification string, the default is number, other supported types are 0 letters 1 numbers 2 uppercase letters 3 lowercase letters 4
Chinese 5 mixed (removed the confusing character oOLl and the number 01)
type: The image type of the verification code, the default is png
width: The width of the verification code. By default, it will be automatically calculated based on the length of the verification code
height: the height of the verification code, the default is 22
verifyName: SESSION record name of the verification code, the default is verify

2. Chinese verification code:

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

The parameters are as follows:

length: The length of the verification code, the default is 4 digits
type: The image type of the verification code, the default is png
width: The width of the verification code. By default, it will be automatically calculated based on the length of the verification code
height: the height of the verification code, the default is 50
fontface: The font file used, use the complete file name or put it in the directory where the image class is located. The default font file used is simhei.ttf (this file can be found under the Fonts directory of the window)
verifyName: SESSION record name of the verification code, the default is verify

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

①.PHP Whether GD library support has been installed;
②. Is there any output before output (especially the BOM header information output of UTF8);
③.Is the Image class library imported correctly?
④. If it is a Chinese verification code, check whether the font file has been copied to the directory where the class library is located;

4.action part:

CommonAction.class.php page code is as follows:

<&#63;php
class CommonAction extends Action{
  function verify(){    
    import('ORG.Util.Image');
    //英文验证码
    //Image::buildImageVerify(5,5,gif,90,30,'verify');
    //中文验证码
    Image::GBVerify();
  }  
  
}
&#63;>

5.view template part:

The template index.html page is as follows:

 验证码:<input type="text" name="verify" /><img  src="/static/imghwm/default1.png"  data-src="__APP__/common/verify"  class="lazy" onclick="show(this)" / alt="ThinkPHP verification code and paging example tutorial, thinkphp example tutorial_PHP tutorial" ><br />
 <input type="submit" value="注册" />
</form>

<script type="text/javascript">
  function show(obj){
    obj.src="__APP__/common/verify/random/"+Math.random();    
  }
</script>

6. Controller:

The controller UserAction.class.php is as follows:

//验证码验证
if($_SESSION['verify']!=md5($_POST['verify'])){
  $this->error('验证码不正确');   
}

2. Pagination:

1. Import the paging class, there is a verification code method in aoliThinkPHPLibORGUtilPage.class.php

2.action part:

UserAction.class.php page is as follows:

function index(){
  import('ORG.Util.Page');//引入分布类
  $user=M('user');
  $count=$user->count();
  $page=new Page($count,3);//一页显示5条
  $page->setConfig('theme','<div style="font-weight:bold;">总共:%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 part:

The template page index.html page is as follows:

<volist name="alist" id="vo">
 <li><span>ID:</span>{$vo['id']}<span>用户名:</span>{$vo['username']}<span>注册ip:</span>{$vo['createip']}<a href="__URL__/del/id/{$vo['id']}">删除</a>  <a href="__URL__/edit/id/{$vo['id']}">编辑</a></li>
</volist>
{$page}

Interested readers can debug and run the ThinkPHP verification code and paging examples in this article. I believe there will be new gains.

How to change web page paging, THINKPHP core, for example: http://wwwttplmgcom/special/8html

Use the setConfig method in the paging class to customize the paging style:
I have a custom paging class that I used before. You can change it here.

/** * * Enter public paging class* @param array $map paging filtering conditions* @param class $Form data model* @param integer $limit number of items displayed in paging* @param string $order Sorting* @return array */ public function _list($map,$Form,$limit=9,$order='add_time'){ $res=array(); $p=empty($_GET['p']) ? 0 : (int)$_GET['p']; $res['list'] = $Form->field(true)->where($map)->order($order)-> page($p.','.$limit)->select();import('ORG.Util.Page'); // Import paging class $count = $Form->where($map)-> ;count();// Query the total number of records that meet the requirements $Page = new Page($count,$limit);// Instantiate the paging class and pass in the total number of records and the number of records displayed on each page $Page-> rollPage=3;$Page->setConfig('theme'," %upPage% %linkPage% %downPage%

  • %nowPage%/%totalPage% page
  • ");$res['page'] = $Page->show();// Display output in paging return $res; }

    How to get the transfer variables of the previous page and next page when thinkphp is paginating? I want to attach the upper and lower page effects to the picture without using the original paging effect.

    public function index() {//Just change the style of the icon $user = M('User'); import('ORG.Util.Page'); $count = $user->count( ); $listRows = 5; $page = new Page($count, $listRows); $list = $user->limit("{$page->firstRow},{$page->listRows}") ->select(); $page->setConfig('prev', 'ThinkPHP verification code and paging example tutorial, thinkphp example tutorial_PHP tutorial');//Previous page $page->setConfig('next', 'ThinkPHP verification code and paging example tutorial, thinkphp example tutorial_PHP tutorial');//Next page// $page-> setConfig('first', ''); // $page->setConfig('last', ''); $page->setConfig('theme', '%upPage% %downPage%');// Only display the upper and lower page options $this->assign('page', $page->show()); $this->assign('list', $list); $this->display(); }

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/868240.htmlTechArticleThinkPHP verification code and paging example tutorial, thinkphp example tutorial This article describes two commonly used functions of ThinkPHP: verification code with pagination. It is very common in ThinkPHP project development, with...
    Statement
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    PHP Email: Step-by-Step Sending GuidePHP Email: Step-by-Step Sending GuideMay 09, 2025 am 12:14 AM

    PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

    How to Send Email via PHP: Examples & CodeHow to Send Email via PHP: Examples & CodeMay 09, 2025 am 12:13 AM

    The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

    Advanced PHP Email: Custom Headers & FeaturesAdvanced PHP Email: Custom Headers & FeaturesMay 09, 2025 am 12:13 AM

    CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

    Guide to Sending Emails with PHP & SMTPGuide to Sending Emails with PHP & SMTPMay 09, 2025 am 12:06 AM

    Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

    What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

    ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

    Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

    The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

    PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

    PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

    PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

    ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    SublimeText3 Linux new version

    SublimeText3 Linux new version

    SublimeText3 Linux latest version

    WebStorm Mac version

    WebStorm Mac version

    Useful JavaScript development tools

    ZendStudio 13.5.1 Mac

    ZendStudio 13.5.1 Mac

    Powerful PHP integrated development environment

    MantisBT

    MantisBT

    Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use