Skip to content

Instantly share code, notes, and snippets.

@CarsonF
Created January 28, 2015 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CarsonF/ea480de052dd28ab48e6 to your computer and use it in GitHub Desktop.
Save CarsonF/ea480de052dd28ab48e6 to your computer and use it in GitHub Desktop.
<?php
if (!isResource()) {
return false;
}
require_once __DIR__ . '/index.php';
function isResource() {
$path = $_SERVER['SCRIPT_NAME'];
$parts = explode('.', $path);
if (empty($parts)) {
return true;
}
$type = end($parts);
if ($type === 'php') {
return true;
}
if (in_array($type, ['yml', 'db', 'twig', 'md'])) {
// Fix PHP built-in server
$_SERVER['SCRIPT_FILENAME'] = __FILE__;
$_SERVER['SCRIPT_NAME'] = '/index.php';
$_SERVER['PHP_SELF'] = '/index.php';
return true;
}
if ($type === 'map') {
return false;
}
if (!file_exists(__DIR__ . $path)) {
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment