1. <?php
  2. // Name: Onefile PHP Script
  3. // Description: One PHP file can host multiple pages with this script.
  4.  
  5. // Usage: index.php?page=1
  6.  
  7. // Original script: Andy @ http://abyssunderground.co.uk
  8. // This script modified by Stephen Lance
  9.  
  10. switch ($_GET['page']) {
  11. case 0:
  12. defaultPage();
  13. break;
  14. case 1:
  15. page1();
  16. break;
  17. case 2:
  18. page2();
  19. break;
  20. case 3:
  21. page3();
  22. break;
  23. default:
  24. defaultPage();
  25. }
  26.  
  27. function defaultPage() {
  28. echo "<HTML><HEAD><TITLE>Default Page</TITLE></HEAD><BODY>";
  29. echo "Here's the HTML for the default page.";
  30. echo "<P>Links:<BR><BR>";
  31. echo "<a href=\"http://{$_SERVER[HTTP_HOST]}{$_SERVER[PHP_SELF]}\">Default Page</a><BR>";
  32. echo "<a href=\"http://{$_SERVER[HTTP_HOST]}{$_SERVER[PHP_SELF]}?page=1\">Page 1</a><BR>";
  33. echo "<a href=\"http://{$_SERVER[HTTP_HOST]}{$_SERVER[PHP_SELF]}?page=2\">Page 2</a><BR>";
  34. echo "<a href=\"http://{$_SERVER[HTTP_HOST]}{$_SERVER[PHP_SELF]}?page=3\">Page 3</a><BR>";
  35. echo "</BODY></HTML>";
  36. }
  37.  
  38. function page1() {
  39. echo "<HTML><HEAD><TITLE>Page 1</TITLE></HEAD><BODY>";
  40. echo "Here's the HTML for the page 1.";
  41. echo "</BODY></HTML>";
  42. }
  43.  
  44. function page2() {
  45. ?>
  46. <HTML>
  47. <HEAD>
  48. <TITLE>
  49. </TITLE>
  50. </HEAD>
  51. <BODY>
  52. <P>Here is the HTML. Don't need to worry about PHP here because we're outside
  53. of the PHP tag. Then before this function ends, we're back in PHP.</P>
  54. <P>Any static content might as well be outside the PHP tags.</P>
  55. <P>To go back inside, just do this: (look at the source code)</P>
  56. <PRE>Page ID: <?php echo $_GET['page']; ?></PRE>
  57. <?php
  58. }
  59.  
  60. function page3() {
  61. header("Content-type: text/plain");
  62. echo "This is just plain text.";
  63. }
  64. ?>