Skip to content

Instantly share code, notes, and snippets.

@walterebert
Last active May 8, 2016 14:00
Show Gist options
  • Save walterebert/54348f67ad5ee7f3a3dfd0f32f4b7782 to your computer and use it in GitHub Desktop.
Save walterebert/54348f67ad5ee7f3a3dfd0f32f4b7782 to your computer and use it in GitHub Desktop.
Simple webmention entry point
<?php
/**
* Receive webmention pings https://www.w3.org/TR/webmention/
*
* @license Creative Commons https://creativecommons.org/publicdomain/zero/1.0/
*/
$statusURL = '';
$data = [];
$request = file_get_contents('php://input');
if ($request) {
mb_parse_str($request, $data);
}
if (isset($data['source'])
&& filter_var($data['source'], FILTER_VALIDATE_URL)
&& isset($data['target'])
&& filter_var($data['target'], FILTER_VALIDATE_URL)
) {
/* TODO: Handle request data */
if ($statusURL) {
// Request was saved
header($_SERVER['SERVER_PROTOCOL'] . ' 201 Created');
header('Location: ' . $statusURL);
header('Content-type: text/plain');
echo 'The Webmention is being processed. You can check on its status here: ' . $statusURL;
} else {
// Handle asynchronously
header($_SERVER['SERVER_PROTOCOL'] . ' 202 Accepted');
header('Content-type: text/plain');
echo 'The Webmention is being processed';
}
} else {
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment