Last active
May 9, 2016 17:15
-
-
Save tranch/a556afec665e7b5648a7d26acdc9c926 to your computer and use it in GitHub Desktop.
A simple router for PHP built-in server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| route('GET', '/', function ($data) { | |
| echo 'Welcome!'; | |
| }); | |
| return false; | |
| function route($method, $uri, $callback) { | |
| $REQUEST_URI = explode('?', $_SERVER["REQUEST_URI"])[0]; | |
| if ($uri == $REQUEST_URI && $method == $_SERVER['REQUEST_METHOD']) { | |
| call_user_func($callback, $_REQUEST); | |
| exit; | |
| } | |
| } |
Author
tranch
commented
May 9, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment