Ik heb een website met een routingsysteem gemaakt en daar het fotoalbumscript van Arjan Kapteijn in geplakt.
(Bedankt Arjan en aanvullers) Dit gaat allemaal goed, behalve wanneer via een link naar een specifiek album wil, krijg ik steeds de Access Forbidden melding. Ik test dit allemaal in een locale omgeving met wampserver.
Ik vermoed dat het probleem zit in het routescript:
<?php
class Router {
static $routes = array();
public static function add($link, $url, $method = null) {
self::$routes[] = [
'link' => $link,
'url' => $url,
'method' => $method
];
}
public static function getArray() {
return self::$routes;
}
public static function name($input) {
foreach (self::$routes as $r) {
if($input == $r['method'] || $input == $r['url'] || $input == $r['link']) {
echo $r['link'];
break;
}
}
}
}
include_once('routes.php');
$configs = array(
'home' => 'index.php',
'pages' => 'pages',
'handler' => 'error.php',
);
$requestURI = explode('/', $_SERVER['REQUEST_URI']);
$scriptName = explode('/', $_SERVER['SCRIPT_NAME']);
for ($i= 0; $i < sizeof($scriptName); $i++) {
if ($requestURI[$i] == $scriptName[$i]) {
unset($requestURI[$i]);
}
}
$command = array_values($requestURI);
var_dump ($command);
$arg0=null; $arg1=null; $arg2 = null;
if(isset($command[0])) {
$arg0=$command[0];
}
if(isset($command[1])) {
$arg1='/'.$command[1].'/';
}
if(isset($command[2])) {
$arg2=$command[2];
}
$url = $arg0.$arg1.$arg2;
if($url == '') {
include_once($configs['pages'].'/'.$configs['home']);
return;
}
$routes = Router::getArray();
foreach ($routes as $route) {
if($url == $route['link']) {
include_once($configs['pages'].'/'.$route['url']);
return;
}
}
include_once('handler/'.$configs['handler']);
?>
Met dit in de .htaccess:
<IfModule mod_rewrite.c>
SetEnv HTTP_MOD_REWRITE On
Options FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ([^/]+)/?$ index.php?id=$1 [NC,L]
RewriteRule ^url\/(.*)\/?$ /index.php?id=Routing&rest=$1 [NC,L]
</IfModule>
Het stukje script waar de link staat om naar een album te gaan:
<?php
if(!$mappen = glob($startmap.'/'.$map.'/*', GLOB_ONLYDIR)) {
$mappen = array();
}
foreach($mappen as $album) {
if(basename($album) != 'thumbs') {
echo '<a href="'.$base_url.basename($album).'">'.ucfirst(basename($album)).'</a><br>'.PHP_EOL;
}
}
?>
De link klopt voor wat er in de adresregel verschijnt, alleen krijg ik dus een forbidden.