Now one of the most popular things that people do with MySQL databases is create Pagination scripts (think index.php?id=1 and index.php?page=derp).
When they use a database, they have their PHP script search the table for the relevant page (AKA "dork") and it will display it accordingly. Simple, right?
Now there are multiple ways to call a page in without using MySQL, and I'll post two ways.
Way #1: Arrays (This way is better in my opinion)
<?php
// Whitelist of valid includes
$Pages = array("links", "projects", "contact", "404");
if (in_array($_GET['id'], $Pages))
{
include $_GET['id'] . ".php";
}
else
{
// 404 code goes here, or echo some HTML
}
?>
Way #2: A series of if-else statements
<?php
$id = $_GET['id'];
if ($id == 'links')
{
include 'links.php';
}
else if ($id == 'privacy')
{
include 'privacy.php';
}
else if ($id =='contact')
{
include 'contact.php';
}
else
{
//404 page here, or echo some HTML
}
?>
Feel free to use either of those snippets, no credit is needed.
If you know any other based pagination methods, please tell me!
Interesting, im a total noob though so i guess its kinda hard to grasp that stuff.
ReplyDelete