Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Minimum viable webmention in PHP.
<?php
# Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
# http://creativecommons.org/publicdomain/zero/1.0/
if (!isset($_POST['source']) || !isset($_POST['target'])) {
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
exit;
}
ob_start();
$ch = curl_init($_POST['source']);
curl_setopt($ch,CURLOPT_USERAGENT,'mydomain (webmention.org)');
curl_setopt($ch,CURLOPT_HEADER,0);
$ok = curl_exec($ch);
curl_close($ch);
$source = ob_get_contents();
ob_end_clean();
header($_SERVER['SERVER_PROTOCOL'] . ' 202 Accepted');
if (stristr($source, $_POST['target'])) {
# Now do something with $source e.g. parse it for h-entry and h-card and store what you find.
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment