Skip to content

Instantly share code, notes, and snippets.

@rohmann
Last active December 21, 2015 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rohmann/6326465 to your computer and use it in GitHub Desktop.
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
<?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