Last active
December 21, 2015 15:28
-
-
Save rohmann/6326465 to your computer and use it in GitHub Desktop.
Ensure a web request is coming from github. Useful for setting up web hooks
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 | |
function githubOrigin() { | |
function netMatch($CIDR,$IP) { | |
list ($net, $mask) = explode ('/', $CIDR); | |
return ( ip2long ($IP) & ~((1 << (32 - $mask)) - 1) ) == ip2long ($net); | |
} | |
return (netMatch("204.232.175.64/27",$_SERVER['REMOTE_ADDR']) || netMatch("192.30.252.0/22",$_SERVER['REMOTE_ADDR'])); | |
} | |
//Make sure this request has come from a github IP | |
if (!githubOrigin()) die('Unauthorized'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment