Last active
December 10, 2015 12:45
-
-
Save robinkanters/1c4622e297a671b31992 to your computer and use it in GitHub Desktop.
PHP debug server router script for Prestashop
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 | |
define('_PS_ADMIN_DIR_', __DIR__.'/iadmin/'); | |
$url = $originalUrl = preg_replace('/^(.*)\?.*$/', '$1', $_SERVER['REQUEST_URI']); | |
$stdout = fopen('php://stdout', 'w'); | |
$stderr = fopen('php://stderr', 'w'); | |
$matches = []; | |
if(preg_match('/^\\/*api\\/(.*)$/', $url, $matches)) { | |
$url = '/webservice/dispatcher.php'; | |
$_GET['url'] = $matches[1]; | |
} | |
$types = [ | |
'css' => 'text/css;charset=utf-8', | |
'js' => 'application/javascript;charset=utf-8', | |
'png' => 'image/png', | |
'jpg' => 'image/jpeg', | |
'jpeg' => 'image/jpeg', | |
'gif' => 'image/gif', | |
'ico' => 'image/x-icon', | |
'woff' => 'application/x-font-woff', | |
'ttf' => 'application/x-font-ttf', | |
]; | |
if(preg_match('/\.php/', $url)) | |
require __DIR__.$url; | |
elseif(preg_match(sprintf('/\.(%s)$/', implode('|', array_keys($types))), $url, $matches)) { | |
$fileToOpen = __DIR__ . $url; | |
header(sprintf('Content-Type: %s', $types[$matches[1]])); | |
header(sprintf('Content-Length: %s', filesize($fileToOpen))); | |
echo file_get_contents($fileToOpen); | |
} | |
$remoteHost = $_SERVER['REMOTE_ADDR']; | |
$remotePort = $_SERVER['REMOTE_PORT']; | |
fwrite($stderr, sprintf('[%s] %s:%S [%s]: %s'.PHP_EOL, date('r', time()), $remoteHost, $remotePort, http_response_code(), $originalUrl)); | |
@fclose($stdout); | |
@fclose($stderr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment