Created
March 18, 2016 09:57
-
-
Save Foxy79/cc4aceb1a71e9cc60f87 to your computer and use it in GitHub Desktop.
DropBox WebHook PHP Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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