<?php
// Name: Onefile PHP Script v.2
// Description: One PHP file can host multiple pages with this script.
// There is also an auto-generation of links to previous and next pages
// Usage: index.php?page=1
// Original script: Andy @ http://abyssunderground.co.uk
// This script modified by Stephen Lance
switch ($_GET['page']) {
case 0: defaultPage(); break;
case 1: page1(); break;
case 2: page2(); break;
case 3: page3(); break;
case 4: page4(); break;
case 5: page5(); break;
case 6: page6(); break;
case 7: page7(); break;
case 8: page8(); break;
case 9: page9(); break;
case 10: page10(); break;
case 11: page11(); break;
case 12: page12(); break;
case 13: page13(); break;
case 14: page14(); break;
case 15: page15(); break;
default: defaultPage();
}
function defaultPage() {
echo "<HTML><HEAD><TITLE>Default Page</TITLE></HEAD><BODY>";
echo "Here's the HTML for the default page.";
echo "<P>Links:<BR><BR>";
echo "<a href=\"http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}\">Default Page</a><BR>";
echo "<a href=\"http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?page=1\">Page 1</a><BR>";
echo "<a href=\"http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?page=2\">Page 2</a><BR>";
echo "<a href=\"http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?page=3\">Page 3</a><BR>";
}
function page1() {
echo "<HTML><HEAD><TITLE>Page 1</TITLE></HEAD><BODY>";
echo "Here's the HTML for the page 1.";
}
function page2() {
?>
<HTML>
<HEAD>
<TITLE>
</TITLE>
</HEAD>
<BODY>
<P>Here is the HTML. Don't need to worry about PHP here because we're outside
of the PHP tag. Then before this function ends, we're back in PHP.</P>
<P>Any static content might as well be outside the PHP tags.</P>
<P>To go back inside, just do this: (look at the source code)</P>
<PRE>Page ID: <?php echo $_GET['page']; ?></PRE>
<?php
}
function page3() {
header("Content-type: text/plain");
echo "This is just plain text.";
}
function page4() {echo "Page 4";}
function page5() {echo "Page 5";}
function page6() {echo "Page 6";}
function page7() {echo "Page 7";}
function page8() {echo "Page 8";}
function page9() {echo "Page 9";}
function page10() {echo "Page 10";}
function page11() {echo "Page 11";}
function page12() {echo "Page 12";}
function page13() {echo "Page 13";}
function page14() {echo "Page 14";}
function page15() {echo "Page 15";}
?>
<?php
// Auto Generation of links for $backpages previous pages and $forwpages forward pages
$page = $_GET['page'];
$totalpages = 16; // You have to manually change this with the amount of pages you have
$backpages = 3; // How many links to previous pages you want to see
$forwpages = 6; // How many links to pages ahead you want to see
echo "<HR>";
if(!$page) {$page = 0;}
// Show [Prev]
if ($page > 1) {echo "<a href=\"$_SERVER[PHP_SELF]?page=".($page-1)."\">[Prev]</a> \n";}
// Show links to previous pages - as long as they exist
if ($page >= ($backpages + 1)) {$back = $backpages;} else {$back = ($page - 1);}
for($i = 1; $i <= $back; $i++)
{echo "<a href=\"$_SERVER[PHP_SELF]?page=".($page + $i - $back - 1)."\">[".($page + $i - $back - 1)."]</a> \n";}
// Show Current Page
echo "<B>[{$page}]</B> \n";
// Show links to pages ahead - as long as they exist
if (($page + $forwpages) <= $totalpages) {$max = $forwpages;} else {$max = ($totalpages - $page);}
for($i = 1; $i <= $max; $i++)
{echo "<a href=\"$_SERVER[PHP_SELF]?page=".($page + $i)."\">[".($page + $i)."]</a> \n";}
// Shoe [Next]
if ($page <= ($totalpages - 1))
{echo "<a href=\"$_SERVER[PHP_SELF]?page=".($page + 1)."\">[Next]</a>\n";}
?>