PHP code example of kiss-php / router

1. Go to this page and download the library: Download kiss-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/ */

    

kiss-php / router example snippets

 apache
RewriteEngine On

# Never execute PHP files from public
RewriteRule ^public/.*\.php$ index.php [L,QSA,NC]

# Serve public non-PHP files directly
RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteCond %{DOCUMENT_ROOT}/public%{REQUEST_URI} -f
RewriteRule ^(.+)$ public/$1 [L]

RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^ index.php [L,QSA]
 nginx
location = /index.php {
    # Your PHP/FPM config here
}

location ~ ^/public/.*\.php$ {
    rewrite ^ /index.php last;
}

location ~ \.php$ {
    rewrite ^ /index.php last;
}

location / {
    try_files /public$uri /index.php;
}
 php
Router::useFolder('img', 'public/images/');
 php
if (in_array($_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) {
    Router::useFolder('/', 'public/');
}
 php
Router::execute('about', '/pages/about.php');
 php
$id = Router::getOption('id');