PHP获取远程web服务器时间的代码
程序员文章站
2022-04-26 21:23:07
...
<?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")); ?>