PHP Classes

How to Implement a PHP Router Script using the Router App: Route HTTP requests to given PHP scripts

Recommend this page to a friend!
  Info   View files Example   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum (4)   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 130 All time: 9,327 This week: 73Up
Version License PHP version Categories
router_app 1.0.2Free for non-comm...5HTTP, PHP 5, Design Patterns
Description 

Author

This package can route HTTP requests to given PHP scripts.

It can register multiple URL patterns and an HTTP request method (GET or POST) that an application is accepting requests.

The package can load a PHP script to execute when it processes a HTTP request when the request URL matches one of the registered URL patterns.

If the current HTTP request does not match any of the registered URL patterns, the package can load and execute a script to handle HTTP status code 404 if that script exists.

Picture of Aladdin
Name: Aladdin <contact>
Classes: 1 package by
Country: Egypt Egypt
Age: 53
All time rank: 432249 in Egypt Egypt
Week rank: 312 Up3 in Egypt Egypt Up

Example

<?php

// This is a simple and powerful Router App like frameworks
// first build your page as you want and need inside components directory .. like home.php or login.php or any you want
// i just biuld home.php, about.php and contact.php for example
// then make a new instance for Router Class
// then use get($route, $pathToFile); for get method
// or use post($route, $pathToFile); for post method
// then run();
// as like bellow

// note: any route doesn't installed as like bellow .. it will response and render a 404 not found page

include_once('./Router/Router.php');

$pages = new Router();
$pages->get('/', './components/home.php');
$pages->get('/about', './components/about.php');
$pages->get('/contact', './components/contact.php');

$pages->run();


Details

routerApp

  • This is a simple and powerful Router App like frameworks
  • first build your page as you want and need inside components directory .. like home.php or login.php or any you want
  • I just biuld home.php, about.php and contact.php for example
  • then make a new instance for Router Class
  • then use get($route, $pathToFile); for get method
  • or use post($route, $pathToFile); for post method
  • then run();
  • as like in index.php
  • note: any route doesn't installed as like in index.php .. it will response and render a 404 not found page

  Files folder image Files  
File Role Description
Files folder imagecomponents (5 files)
Files folder imageRouter (1 file)
Plain text file .htaccess Aux. useful magic server tool
Plain text file index.php Example Example script
Plain text file README.md Doc. Documentation

  Files folder image Files  /  components  
File Role Description
  Plain text file about.php Aux. Auxiliary script
  Plain text file contact.php Aux. Auxiliary script
  Plain text file home.php Aux. Auxiliary script
  Plain text file index.php Aux. Auxiliary script
  Plain text file _404.php Aux. Auxiliary script

  Files folder image Files  /  Router  
File Role Description
  Plain text file Router.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 88%
Total:130
This week:0
All time:9,327
This week:73Up
User Comments (2)
Very well done!
1 year ago (Roberto del Pino)
80%StarStarStarStarStar
very easy and good work
1 year ago (Aladdin Masoud)
80%StarStarStarStarStar