首页 >php教程 >PHP源码 >判断域名过期时间

判断域名过期时间

PHP中文网
PHP中文网原创
2016-05-26 08:19:001796浏览

php代码

#!/usr/bin/env php
<?php

define("NOTIFY_DAYS", 30);
define(&#39;EMAIL&#39;, &#39;youemail@qq.com&#39;);

$domains = array(
	&#39;domain1.com&#39;,
	&#39;domain2.com&#39;,
);

function alert($domain,$days)
{
    mail(EMAIL, &#39;Domain Expire Waring - &#39; . $domain, sprintf("%s will expired in %s days", $domain, $days));
}

function check_doamin_expire($domain)
{
	exec(sprintf("/usr/bin/whois %s", $domain), $arr, $retCode);

	if ($retCode == 0)
	{
		$pattern = array (
			&#39;/^Registry Expiry Date:\s*(.+)$/&#39;,
			&#39;/^Registrar Registration Expiration Date:\s*(.+)$/&#39;
		);

	    $exp_date = array_values(preg_filter($pattern, "$1", $arr));
	    $remain_time = strtotime($exp_date[0]) - time();
	    $days = intval($remain_time/86400);
	    if ( $remain_time < NOTIFY_DAYS*86400)
	    {
	        alert($domain,$days);
	    }
	}
}

foreach ($domains as $domain)
{
	check_doamin_expire($domain);
}

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn