You are here

public function CleantalkSFW::sfw_die in Anti Spam by CleanTalk 7.5

Same name and namespace in other branches
  1. 7.2 cleantalk.module \CleanTalkSFW::sfw_die()
  2. 7.4 src/CleantalkSFW.php \CleantalkSFW::sfw_die()

File

src/CleantalkSFW.php, line 218

Class

CleantalkSFW

Code

public function sfw_die($api_key, $cookie_prefix = '', $cookie_domain = '') {

  // File exists?
  if (file_exists(dirname(__FILE__) . "/sfw_die_page.html")) {
    $sfw_die_page = file_get_contents(dirname(__FILE__) . "/sfw_die_page.html");
  }
  else {
    print "IP BLACKLISTED";
    die;
  }

  // Service info
  $sfw_die_page = str_replace('{REMOTE_ADDRESS}', $this->blocked_ip, $sfw_die_page);
  $sfw_die_page = str_replace('{REQUEST_URI}', $_SERVER['REQUEST_URI'], $sfw_die_page);
  $sfw_die_page = str_replace('{SFW_COOKIE}', md5($this->blocked_ip . $api_key), $sfw_die_page);

  // Headers
  if (headers_sent() === false) {
    header('Expires: ' . date(DATE_RFC822, mktime(0, 0, 0, 1, 1, 1971)));
    header('Cache-Control: no-store, no-cache, must-revalidate');
    header('Cache-Control: post-check=0, pre-check=0', FALSE);
    header('Pragma: no-cache');
    header("HTTP/1.0 403 Forbidden");
    $sfw_die_page = str_replace('{GENERATED}', "", $sfw_die_page);
  }
  else {
    $sfw_die_page = str_replace('{GENERATED}', "<h2 class='second'>The page was generated at&nbsp;" . date("D, d M Y H:i:s") . "</h2>", $sfw_die_page);
  }
  print $sfw_die_page;
  die;
}