对于已经运营了一段时间的网站来说,突然备案要关闭网站,会令大多数人都很烦劳~

wordpress要做到备案不关站,从苏醒的博客我知道这样一个办法——屏蔽管局地区

新建一个ipget.php文件,把下面的代码输入php文件中。

        

<?php

function get_client_ip() {

if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))

$ip = getenv("HTTP_CLIENT_IP");

else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"),

"unknown"))

$ip = getenv("HTTP_X_FORWARDED_FOR");

else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))

$ip = getenv("REMOTE_ADDR");

else if (isset ($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR']

&& strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))

$ip = $_SERVER['REMOTE_ADDR'];

else

$ip = "unknown";

return ($ip);

}

header("Content-type: text/html; charset=utf-8");

$verification = '江西省';

$ip = get_client_ip(); //获取当前用户的ip

$antecedents = $_SERVER['HTTP_REFERER'];//访客来路地址

$result = file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=".$ip);//IP数据库来自淘宝。

$address = json_decode($result,true);

if($address['data']['region'] == $verification && strpos($antecedents, 'baidu') === false && strpos($antecedents, 'google') === false){

sleep(9999999999999999);

ob_start();

header('HTTP/1.1 503 Service Temporarily Unavailable');

header('Status: 503 Service Temporarily Unavailable');

header('Retry-After: 3600');

header('X-Powered-By:NaiZui');

echo '网站备案中....';

exit;

}

?>

在wordpress主题header.php中调用

<?php include( 'ipget.php' );?>

即可。本文转载至苏醒的博客 suxing.me