Skip to content

Instantly share code, notes, and snippets.

@ziadoz ziadoz/index.php
Last active Aug 29, 2015

Embed
What would you like to do?
Simple PHP HTTP Handling
<?php
// See Error Handling in PHP: https://nomadphp.com/2015/02/25/nomadphp-2015-02-us-lt2/#
$display = function ($status, $headers = array(), $content = '') {
http_response_code($status);
foreach ($headers as $key => $value) {
header($key . ': ' . $value);
}
echo $content;
};
$dispatch = function ($display, $response) {
return call_user_func_array($display, $response);
};
$controller = function ($get, $post, $cookie, $server) {
$content = '<p>Hello, ' . (isset($get['name']) ? $get['name'] : 'World') . '!</p>';
return array(200, array('X-Powered-By' => 'Awesome'), $content);
};
$dispatch($display, $controller($_GET, $_POST, $_COOKIE, $_SERVER));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.