Skip to content

Instantly share code, notes, and snippets.

@Foxy79
Created March 18, 2016 09:57
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Foxy79/cc4aceb1a71e9cc60f87 to your computer and use it in GitHub Desktop.
Save Foxy79/cc4aceb1a71e9cc60f87 to your computer and use it in GitHub Desktop.
DropBox WebHook PHP Sample
<?php
define ('SECRET', 'Your_secret_here');
if (isset($_GET['challenge'])) {
echo $_GET['challenge'];
} else {
$raw_data = file_get_contents('php://input');
if ($raw_data) {
$json = json_decode($raw_data);
if (is_object($json)) {
if (isset($json->list_folder)) {
$headers = getallheaders();
if (hash_hmac("sha256",$raw_data,SECRET) == $headers['X-Dropbox-Signature']) {
// Do something
exit();
}
}
}
}
header('HTTP/1.0 403 Forbidden');
}
if (!function_exists('getallheaders')) {
function getallheaders() {
$headers = '';
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
return $headers;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment