Last active
October 3, 2015 09:50
-
-
Save RyanHarijanto/dcff63f73ee3f4a929b0 to your computer and use it in GitHub Desktop.
BlockThem PHP Example
This file contains 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 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