Give us a second

SIMPLE AND COMPLETE PHP ROUTING LIBRARY

Best PHP Routing library in less than 1 kilobyte

Download PHP ROUTER

Note: Your code and the PhpRouter library must be placed under the root folder of your application/domain

NEW - Simple examples with callbacks


// Test page
// Runs a callback directly
get('/test', function(){
  echo 'Awesome!';
});

// Runs a callback directly
get('/box/admin', function(){
  header('Location: /box/admin/dashboard');
});

After the function is run, the code exits. So nothing else happens. Simple!

Simple examples to get started fast


// Index page
get('/', 'index.php');

// Contact us page
get('/contact-us', 'contact-us.php');

// All products
get('/products', 'products.php');

// Products for children
get('/children', 'children-products.php');

// Male or female products
// $gender could be male or female
get('/products/$gender', 'products.php');

// Signup
post('/signup', 'signup.php');

// Login
post('/login', 'login.php');

Check out the menu to read more, or this quick links to learn more about our routing library:

Why this routing library?

While building the library I decided to keep it as simple and yet secure and complete as possible. The intention is to facilitate the creation of PHP routes/routing and not to create a full framework or anything complex to use and understand.

Check out the menu to read more, or this quick links to learn more about our routing library:

GET static routes

GET dynamic routes

POST routes

Query Strings and Friendly URLs

The routes also support query strings. This means that along the url a request can contain variables. For example: phprouter.com?name=a&last_name=b

What is included in this PHP routing library?

Download PHP ROUTER. It contains 3 files. Please give a star ☆ on Github!

.htaccess

Contains 3 lines of code and tells the server to allow direct access to files ending with specific extensions. Also tells the server to redirect all requests to the routes file.

routes.php

All the routes must be defined in this file. The following HTTP methods can be defined: get, post, delete, and any. There is no need to use PUT or PATCH, since it is better to use those options by replacing them with POST.

router.php

This small file, with less than 60 lines of code, is the heart of the PHP routing library.