1. Go to this page and download the library: Download khantloonthu/php-router library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
function checkLoggedIn($request) {
global $isLoggedIn;
if (!$isLoggedIn) {
return ['status' => 401, 'message' => 'Unauthorized: Please log in.'];
}
return true; // continue processing
}
$router->middleware('checkLoggedIn');
// or anonymous function style
$router->middleware(function ($request) {
global $isLoggedIn;
if (!$isLoggedIn) {
return false; // triggers 403 Forbidden by default
}
return true;
});
$router->get('/dashboard', function () {
return false;
if (!$isAdmin) return false;
return true;
}
]);
$router->post('/create-user', function () use ($router) {
$isAdmin = false;
if (!$isAdmin) {
$router->abort(403);
}
// continue with user creation...
});
$router->post('/send-mail', function () use ($router) {
// send mail logic
$mail->send();
$router->redirect('/');
});
$router->handle(404, function() {
return
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.