Beautiful PHP verification code

Source: Internet
Author: User
Beautiful PHP verification code

  1. Class Page {
  2. Private $ total; // total records
  3. Private $ pagesize; // The number of entries displayed on each page
  4. Private $ limit; // limit
  5. Private $ page; // The current page number.
  6. Private $ pagenum; // the total page number.
  7. Private $ url; // address
  8. Private $ bothnum; // The number of numeric pages on both sides
  9. // Constructor initialization
  10. Public function _ construct ($ _ total, $ _ pagesize ){
  11. $ This-> total = $ _ total? $ _ Total: 1;
  12. $ This-> pagesize = $ _ pagesize;
  13. $ This-> pagenum = ceil ($ this-> total/$ this-> pagesize );
  14. $ This-> page = $ this-> setPage ();
  15. $ This-> limit = "LIMIT". ($ this-> page-1) * $ this-> pagesize. ", $ this-> pagesize ";
  16. $ This-> url = $ this-> setUrl ();
  17. $ This-> bothnum = 2;
  18. }
  19. // Interceptor
  20. Private function _ get ($ _ key ){
  21. Return $ this-> $ _ key;
  22. }
  23. // Obtain the current page number
  24. Private function setPage (){
  25. If (! Empty ($ _ GET ['Page']) {
  26. If ($ _ GET ['Page']> 0 ){
  27. If ($ _ GET ['Page']> $ this-> pagenum ){
  28. Return $ this-> pagenum;
  29. } Else {
  30. Return $ _ GET ['Page'];
  31. }
  32. } Else {
  33. Return 1;
  34. }
  35. } Else {
  36. Return 1;
  37. }
  38. }
  39. // Obtain the address
  40. Private function setUrl (){
  41. $ _ Url = $ _ SERVER ["REQUEST_URI"];
  42. $ _ Par = parse_url ($ _ url );
  43. If (isset ($ _ par ['query']) {
  44. Parse_str ($ _ par ['query'], $ _ query );
  45. Unset ($ _ query ['Page']);
  46. $ _ Url = $ _ par ['path']. '? '. Http_build_query ($ _ query );
  47. }
  48. Return $ _ url;
  49. } // Numeric Directory
  50. Private function pageList (){
  51. For ($ I = $ this-> bothnum; $ I >=1; $ I --){
  52. $ _ Page = $ this-> page-$ I;
  53. If ($ _ page <1) continue;
  54. $ _ Pagelist. = 'URL. '& page ='. $ _ page. '">'. $ _ page .'';
  55. }
  56. $ _ Pagelist. = ''. $ this-> page .'';
  57. For ($ I = 1; $ I <= $ this-> bothnum; $ I ++ ){
  58. $ _ Page = $ this-> page + $ I;
  59. If ($ _ page> $ this-> pagenum) break;
  60. $ _ Pagelist. = 'URL. '& page ='. $ _ page. '">'. $ _ page .'';
  61. }
  62. Return $ _ pagelist;
  63. }
  64. // Homepage
  65. Private function first (){
  66. If ($ this-> page> $ this-> bothnum + 1 ){
  67. Return 'URL. '"> 1 ...';
  68. }
  69. }
  70. // Previous Page
  71. Private function prev (){
  72. If ($ this-> page = 1 ){
  73. Return 'previous page ';
  74. }
  75. Return 'URL. '& page ='. ($ this-> page-1). '"> Previous page ';
  76. }
  77. // Next page
  78. Private function next (){
  79. If ($ this-> page ==$ this-> pagenum ){
  80. Return 'next page ';
  81. }
  82. Return 'URL. '& page ='. ($ this-> page + 1). '"> Next page ';
  83. }
  84. // Last Page
  85. Private function last (){
  86. If ($ this-> pagenum-$ this-> page> $ this-> bothnum ){
  87. Return '... url.' & page = '. $ this-> pagenum.' "> '. $ this-> pagenum .'';
  88. }
  89. }
  90. // Paging information
  91. Public function showpage (){
  92. $ _ Page. = $ this-> first ();
  93. $ _ Page. = $ this-> pageList ();
  94. $ _ Page. = $ this-> last ();
  95. $ _ Page. = $ this-> prev ();
  96. $ _ Page. = $ this-> next ();
  97. Return $ _ page;
  98. }
  99. }
  100. ?>


Shows the paging style:

Instructions for use:

  1. $ _ Page = new Page ($ _ total, $ _ pagesize); // where $ _ total indicates the total number of data sets, and $ _ pagesize indicates the number displayed on each page.
  2. ?>


Verification code, PHP

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.