Last active
          August 29, 2015 14:18 
        
      - 
      
 - 
        
Save viralvadgama/3cdd6ab73f9d58e99a95 to your computer and use it in GitHub Desktop.  
    Git-hub Web hook - PHP
  
        
  
    
      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 | |
| // Content Type: application/json | |
| $time = time(); | |
| $secret = '<your-secret-here>'; | |
| $headers = getallheaders(); | |
| $hubSignature = @$headers['X-Hub-Signature']; | |
| if ($hubSignature != '') | |
| { | |
| list($algo, $hash) = @explode('=', $hubSignature, 2); | |
| $payload = file_get_contents('php://input'); | |
| if (isset($algo) and isset($hash)) | |
| { | |
| if ($algo != '' and $hash != '') | |
| { | |
| $payloadHash = hash_hmac($algo, $payload, $secret); | |
| } | |
| else | |
| { | |
| die('Bad request'); | |
| } | |
| if ($hash !== $payloadHash) | |
| { | |
| die('Bad request'); | |
| } | |
| } | |
| else | |
| { | |
| die('Bad request'); | |
| } | |
| } | |
| else | |
| { | |
| die('Bad request'); | |
| } | |
| echo "Webhook received.\nTimestamp: {$time}\n--- start ---"; | |
| $data = json_decode($payload); | |
| // process data | |
| echo "\n\n--- done ---"; | |
| ?> | |
| /* on Success Response | |
| Webhook received. | |
| Timestamp: 1427803925 | |
| --- start --- | |
| --- done --- | |
| */ | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment