/** * Convenience function for a quick check if the headers indicate a XHR (AJAX) request. * Basically checks the `x-requested-with` header. * * @return bool true if the current request is an XHR request, false otherwise */ function is_xhr() { static $is_xhr = null; if ($is_xhr === null) { if (strtolower(request_headers('x-requested-with')) === 'xmlhttprequest') { $is_xhr = true; } else { $is_xhr = false; } } return $is_xhr; }
header("Location: " . $xmlfile); } } else { restore_error_handler(); $filepointer = @fopen($ofsfile, "rb"); if ($filepointer) { $JpegOfs = unserialize(fread($filepointer, filesize($ofsfile))); fclose($filepointer); $face = array_key_exists("face", $_GET) ? $_GET["face"] : "left"; $x_ofs = array_key_exists("x_ofs", $_GET) ? $_GET["x_ofs"] : "0"; $y_ofs = array_key_exists("y_ofs", $_GET) ? $_GET["y_ofs"] : "0"; $jpgstart = $JpegOfs[$face][$x_ofs][$y_ofs]["pstart"]; $jpglength = $JpegOfs[$face][$x_ofs][$y_ofs]["plength"]; // Getting headers sent by the client. //$headers = apache_request_headers(); $headers = request_headers(); $CacheFileTime = max(filemtime($file), filemtime($ofsfile)); // Checking if the client is validating his cache and if it is current. if (isset($headers['If-Modified-Since']) && strtotime($headers['If-Modified-Since']) == $CacheFileTime) { // Client's cache IS current, so we just respond '304 Not Modified'. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $CacheFileTime) . ' GMT', true, 304); } else { // Image not cached or cache outdated, we respond '200 OK' and output the image. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $CacheFileTime) . ' GMT', true, 200); header("Expires: Mon, 24 Jul 2017 05:00:00 GMT"); // Date in the future header("Accept-Ranges: bytes"); header("Content-Type: image/jpeg"); header("Content-Length: {$jpglength}"); header("Content-Disposition: inline; filename=tile_{$x_ofs}_{$y_ofs}.jpg"); fseek($fp, $jpgstart);
}); on('GET', '/redirect/301', function () { redirect('/index', 301); }); filter('id', function () { echo "id found"; }); on('GET', '/index/:id', function ($id) { echo "id = {$id}"; }); on('GET', '/cookie-set', function () { cookie('cookie', '123'); echo "cookie set"; }); on('POST', '/request-headers', function () { echo request_headers('content-type'); $body = request_body(); echo "name={$body['name']}"; }); on('GET', '/cookie-get', function () { $value = cookie('cookie'); echo "cookie={$value}"; }); on('GET', '/params', function () { $one = params('one'); $two = params('two'); echo "one={$one}" . PHP_EOL; echo "two={$two}" . PHP_EOL; }); on('GET', '/flash-set', function () { flash('message', 'success');