secret) header('HTTP/1.0 403 Forbidden'); else { $all_calendars = ""; foreach ($data->calendars as &$calendar) { $ical = file_get_contents($calendar); $all_calendars = $all_calendars . $ical; } unset($calendar); $pattern = "/(\r?)\nEND:VCALENDARBEGIN:VCALENDAR/"; $replacement = ""; $all_calendars = preg_replace($pattern, $replacement, $all_calendars); $calendar_filename = "calendar.ics"; file_put_contents($calendar_filename, $all_calendars); header("Content-disposition: attachment;filename=$calendar_filename"); header('Content-Type: text/calendar'); readfile($calendar_filename); ob_end_flush(); flush(); unlink($calendar_filename); } ?>