首页 > Other > PHP获取远程web服务器时间的代码

PHP获取远程web服务器时间的代码

<?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]);
}
echo date(‘Y-m-d H:i:s’,get_time(“www.163.com”));
?>

分类:Other
  1. 还没有评论。
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: