Skip to content

Instantly share code, notes, and snippets.

@underwhelmed
Created October 21, 2011 03:06
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 underwhelmed/1303015 to your computer and use it in GitHub Desktop.
Save underwhelmed/1303015 to your computer and use it in GitHub Desktop.
Tumblr Psuedo Blocking By IP
<?php
function GetIP()
{
foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key)
{
if (array_key_exists($key, $_SERVER) === true)
{
foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip)
{
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false)
{
return $ip;
}
}
}
}
}
if (($_SERVER['HTTP_REFERER'] == '') || (GetIP() == "47.33.133.24")) { /* IP Address to "block" - add more || (GetIP() == "47.33.133.24") before the last parenthesis to add more ip addresses */
header("Location: www.youtube.com/watch?v=v1PBptSDIh8");
}
else {
header("Location: " . $_SERVER['HTTP_REFERER'] . "?d=1");
}
exit();
?>
...add this snippet somewhere in the <head> tag for your theme
<script type="text/javascript">
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
if (getParameterByName("d") != 1) {
location.href = "http://<yourserverurl>/ip_check.php";
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment