An example of router script is:
<?php
// router.php
if (preg_match('/\.(?:png|jpg|jpeg|gif)$/', $_SERVER["REQUEST_URI"])) {
return false; // serve the requested resource as-is.
} //the rest of you code goes here.
php -S localhost:80
PHP 7.1.7 Development Server started at Fri Jul 14 15:11:05 2017
Listening on http://localhost:80
Document root is C:\projetos\repgeral
Press Ctrl-C to quit.
This is the simplest way to start a PHP server that responds to request made to localhost at the port 80.
The -S tells that we are starting a webserver.
The localhost:80 indicates the host that we are answering and the port. You can use other combinations like:
php -S localhost:80 -t project/public router.php
PHP 7.1.7 Development Server started at Fri Jul 14 15:22:25 2017
Listening on http://localhost:80
Document root is /home/project/public
Press Ctrl-C to quit.
Column | Column |
---|---|
-S | Tell the php that we want a webserver |
<hostname>:<port> | The host name and the por to be used |
-t | Public directory |
<filename> | The routing script |