Using Klein-PHP to filter requests

asaini

I am using Klein.php for routing in my PHP project. My project directory has following structure:

myProject
|
*---Restricted--
|              |
|              *---index.php
|              |
|              *---blah.html
|              |
|              *---some_directory
|
|
*---some_other_directories
|
*---index.html
|
*---fun.html
|
*---css
|
*---js

What I want is to process all request to the Restricted folder only. For everything else I simply want the server to do its job, i.e. simply serve rest of the files.

How do I achieve that?

Edit

I have it configured as give in answer by CORY:

// .htaccess file

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]

and

// index.php

<?php

    require_once __DIR__ . '/vendor/autoload.php';

    $klein = new \Klein\Klein();

    $klein->respond('@^/Restricted/', function () {
       // checking if authenticated user
    });

    $klein->dispatch();

?>
Cᴏʀʏ

Right on the Github page for Klein.php there's this little example in the Routing section:

// Match all requests that _don't_ start with /admin
$klein->respond('!@^/admin/', ...

I think you basically want the opposite (match all requests that do start with /restricted), so let's remove the ! (negation) and substitute the right folder name:

// Match all requests that start with /Restricted
$klein->respond('@^/Restricted/', ...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related