Nice PHP verification code class

Source: Internet
Author: User
  1. Class Page {
  2. Private $total; Total Records
  3. Private $pagesize; How many bars are displayed per page
  4. Private $limit; Limit
  5. Private $page; Current page number
  6. Private $pagenum; Total Page number
  7. Private $url; Address
  8. Private $bothnum; The amount of digital paging is maintained on both sides
  9. Constructor method 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. Interception device
  20. Private Function __get ($_key) {
  21. return $this->$_key;
  22. }
  23. Get 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. Get 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. }//Digital 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. Home
  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
  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. ?>
Copy Code
The paging style looks like this:

Instructions for use:

    1. $_page = new page ($_total,$_pagesize); Where $_total is the total number of bars in the dataset, $_pagesize is the number displayed per page.
    2. ?>
Copy Code
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.