Home >php教程 >PHP源码 >PHP获取远程web服务器时间的代码

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

PHP中文网
PHP中文网Original
2016-05-25 17:13:131769browse

<?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 = &#39;&#39;;   
    while ($fp && !feof($fp))   
        $resp .= fread($fp, 1024);   
    preg_match(&#39;/^Date: (.*)$/mi&#39;,$resp,$matches);   
    return strtotime($matches[1]);   
}   
echo date(&#39;Y-m-d H:i:s&#39;,get_time("www.163.com"));   
?>


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