Skip to content

Instantly share code, notes, and snippets.

@RyanHarijanto
Last active October 3, 2015 09:50
Show Gist options
  • Save RyanHarijanto/dcff63f73ee3f4a929b0 to your computer and use it in GitHub Desktop.
Save RyanHarijanto/dcff63f73ee3f4a929b0 to your computer and use it in GitHub Desktop.
BlockThem PHP Example
<?php
function isDomainBlocked($domain, $jsonFile) {
$domain = preg_replace('/^http(s?)\:\/\//', '', $domain);
$domain = preg_replace('/^www\./', '', $domain);
$domain = preg_replace('/\/$/', '', $domain);
$list = json_decode(file_get_contents($jsonFile), true);
return in_array($domain, $list);
}
// Example: Live
// Output: bool(false)
var_dump(isDomainBlocked('gmail.com', 'http://api.blockthem.io/v1/blacklist.json'));
// Example: Cached
// Output: bool(true)
var_dump(isDomainBlocked('mailinator.com', 'blacklist.json'));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment