karadav/www/_router.php

36 lines
757 B
PHP
Raw Normal View History

2022-08-31 06:06:27 +00:00
<?php
namespace KaraDAV;
require_once __DIR__ . '/_inc.php';
2022-08-31 07:57:49 +00:00
$uri = strtok($_SERVER['REQUEST_URI'], '?');
2022-08-31 06:06:27 +00:00
if (PHP_SAPI == 'cli-server') {
2022-08-31 07:57:49 +00:00
if (is_file(__DIR__ . '/' . $uri)) {
2022-08-31 06:06:27 +00:00
return false;
}
// Index.php
2022-08-31 07:57:49 +00:00
elseif ($uri == '/') {
2022-08-31 06:06:27 +00:00
return false;
}
2022-08-31 07:57:49 +00:00
2022-09-03 04:25:02 +00:00
$method = $_SERVER['REQUEST_METHOD'] ?? $_SERVER['REDIRECT_REQUEST_METHOD'];
file_put_contents('php://stderr', sprintf("%s %s\n", $method, $uri));
if ($method != 'GET' && $method != 'HEAD') {
file_put_contents('php://stderr', file_get_contents('php://input') . "\n");
}
2022-08-31 06:06:27 +00:00
}
2022-09-04 00:27:40 +00:00
if (isset($_SERVER['REDIRECT_REQUEST_METHOD'])) {
$_SERVER['REQUEST_METHOD'] = $_SERVER['REDIRECT_REQUEST_METHOD'];
}
2022-08-31 06:06:27 +00:00
$s = new Server;
2022-08-31 07:57:49 +00:00
if (!$s->route($uri)) {
2022-08-31 06:06:27 +00:00
http_response_code(404);
echo '<h1>Invalid URL</h1>';
}