So I just started learning PHP and I was making a local project to test it out.
I'm using the built in webserver
https://www.php.net/manual/en/features.commandline.webserver.php
using the command php -S localhost:8000 router.php
And I wanted to navigate to my test.php file which is next to my index.php file at http://localhost:8000/test
But it only works if I use http://localhost:8000/test.php
On the in built webserver page it mentioned how to serve a .el file
So from that I came up with
<?php
// router.php
$pathName = $_SERVER['REQUEST_URI'];
$pathName = str_replace("/", "\\", $pathName);
$file = __DIR__ . $pathName . ".php";
if(file_exists($file)){
include($file);
}else{
return false;
}
?>
But it doesn't seem right.
How would I go about doing it the right way? Can anyone point me in the right direction? Couldn't find anything on stackoverflow but it's probably just because I don't know what to search for.
EDIT: I do want the include functionality and not readfile, I was just wondering if the approach to checking whether the .php file was there was the right one.