PHP获取远程网站的服务器时间

<?php

function get_time($server){

$data  = "HEAD / HTTP/1.1\r\n";

$data .= "Host: $server\r\n";

$data .= "Connection: Close\r\n\r\n";

$fp = fsockopen($server, 80);

fputs($fp, $data);

$resp = '';

while ($fp && !feof($fp))

$resp .= fread($fp, 1024);

preg_match('/^Date: (.*)$/mi',$resp,$matches);

return strtotime($matches[1]);

}

?>


<?php

echo date('Y-m-d H:i:s',get_time("127.0.0.1"));

?>

http://www.codefans.net/articles/1220.shtml

posted @ 2016-04-05 11:00  784040932  阅读(136)  评论(0编辑  收藏  举报