Home  >  Article  >  php教程  >  判断域名过期时间

判断域名过期时间

PHP中文网
PHP中文网Original
2016-05-26 08:19:001745browse

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);
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn