1. <?php
  2. // Name: Onefile PHP Script v.2
  3. // Description: One PHP file can host multiple pages with this script.
  4. // There is also an auto-generation of links to previous and next pages
  5.  
  6. // Usage: index.php?page=1
  7.  
  8. // Original script: Andy @ http://abyssunderground.co.uk
  9. // This script modified by Stephen Lance
  10.  
  11. switch ($_GET['page']) {
  12. case 0: defaultPage(); break;
  13. case 1: page1(); break;
  14. case 2: page2(); break;
  15. case 3: page3(); break;
  16. case 4: page4(); break;
  17. case 5: page5(); break;
  18. case 6: page6(); break;
  19. case 7: page7(); break;
  20. case 8: page8(); break;
  21. case 9: page9(); break;
  22. case 10: page10(); break;
  23. case 11: page11(); break;
  24. case 12: page12(); break;
  25. case 13: page13(); break;
  26. case 14: page14(); break;
  27. case 15: page15(); break;
  28. default: defaultPage();
  29. }
  30.  
  31. function defaultPage() {
  32. echo "<HTML><HEAD><TITLE>Default Page</TITLE></HEAD><BODY>";
  33. echo "Here's the HTML for the default page.";
  34. echo "<P>Links:<BR><BR>";
  35. echo "<a href=\"http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}\">Default Page</a><BR>";
  36. echo "<a href=\"http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?page=1\">Page 1</a><BR>";
  37. echo "<a href=\"http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?page=2\">Page 2</a><BR>";
  38. echo "<a href=\"http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?page=3\">Page 3</a><BR>";
  39. echo "</BODY></HTML>";
  40. }
  41.  
  42. function page1() {
  43. echo "<HTML><HEAD><TITLE>Page 1</TITLE></HEAD><BODY>";
  44. echo "Here's the HTML for the page 1.";
  45. echo "</BODY></HTML>";
  46. }
  47.  
  48. function page2() {
  49. ?>
  50. <HTML>
  51. <HEAD>
  52. <TITLE>
  53. </TITLE>
  54. </HEAD>
  55. <BODY>
  56. <P>Here is the HTML. Don't need to worry about PHP here because we're outside
  57. of the PHP tag. Then before this function ends, we're back in PHP.</P>
  58. <P>Any static content might as well be outside the PHP tags.</P>
  59. <P>To go back inside, just do this: (look at the source code)</P>
  60. <PRE>Page ID: <?php echo $_GET['page']; ?></PRE>
  61. <?php
  62. }
  63.  
  64. function page3() {
  65. header("Content-type: text/plain");
  66. echo "This is just plain text.";
  67. }
  68.  
  69. function page4() {echo "Page 4";}
  70. function page5() {echo "Page 5";}
  71. function page6() {echo "Page 6";}
  72. function page7() {echo "Page 7";}
  73. function page8() {echo "Page 8";}
  74. function page9() {echo "Page 9";}
  75. function page10() {echo "Page 10";}
  76. function page11() {echo "Page 11";}
  77. function page12() {echo "Page 12";}
  78. function page13() {echo "Page 13";}
  79. function page14() {echo "Page 14";}
  80. function page15() {echo "Page 15";}
  81. ?>
  82.  
  83. <?php
  84. // Auto Generation of links for $backpages previous pages and $forwpages forward pages
  85. $page = $_GET['page'];
  86.  
  87. $totalpages = 16; // You have to manually change this with the amount of pages you have
  88. $backpages = 3; // How many links to previous pages you want to see
  89. $forwpages = 6; // How many links to pages ahead you want to see
  90.  
  91. echo "<HR>";
  92. if(!$page) {$page = 0;}
  93.  
  94. // Show [Prev]
  95. if ($page > 1) {echo "<a href=\"$_SERVER[PHP_SELF]?page=".($page-1)."\">[Prev]</a>&nbsp;\n";}
  96.  
  97. // Show links to previous pages - as long as they exist
  98. if ($page >= ($backpages + 1)) {$back = $backpages;} else {$back = ($page - 1);}
  99. for($i = 1; $i <= $back; $i++)
  100. {echo "<a href=\"$_SERVER[PHP_SELF]?page=".($page + $i - $back - 1)."\">[".($page + $i - $back - 1)."]</a>&nbsp;\n";}
  101.  
  102. // Show Current Page
  103. echo "<B>[{$page}]</B>&nbsp;\n";
  104.  
  105. // Show links to pages ahead - as long as they exist
  106. if (($page + $forwpages) <= $totalpages) {$max = $forwpages;} else {$max = ($totalpages - $page);}
  107. for($i = 1; $i <= $max; $i++)
  108. {echo "<a href=\"$_SERVER[PHP_SELF]?page=".($page + $i)."\">[".($page + $i)."]</a>&nbsp;\n";}
  109.  
  110. // Shoe [Next]
  111. if ($page <= ($totalpages - 1))
  112. {echo "<a href=\"$_SERVER[PHP_SELF]?page=".($page + 1)."\">[Next]</a>\n";}
  113. ?>