Skip to content

Instantly share code, notes, and snippets.

@adactio
Last active March 16, 2024 22:15
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save adactio/6484118 to your computer and use it in GitHub Desktop.
Save adactio/6484118 to your computer and use it in GitHub Desktop.
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.
}
?>
@tantek
Copy link

tantek commented Sep 8, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment