// Initial Page Setup:
$page = (!array_key_exists('page', array_flip(REQUEST)) ? 1 : REQUEST[array_search('page', array_keys(array_flip(REQUEST)))+1] );
$pageSetup = [
'previous' => $page-1,
'current' => $page,
'next' => $page+1,
'start' => ($page-1) * resultsPerPage,
];
Trying to get the page number from a url formatted as:
https://myURL/some/path/to/page/2/
I am searching the array for the 'page' array position so I don't have to always rely on the position of the request.
REQUEST is coming from Jason's function:
(function() {
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
if (strpos($path, '..')) die('Hacking Attempt Detected, Aborting');
$path = str_replace(['\\', '%5C'], '/', substr(
$path,
strlen(pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_DIRNAME))
));
if (empty($path))
define('REQUEST', [ 'index' ]);
else {
$path = explode('/', $path);
foreach ($path as &$p) $p = urldecode($p);
define('REQUEST', $path);
}
})();