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

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

PHP中文网
Release: 2016-05-25 17:13:13
Original
1767 people have browsed it

<?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"));   
?>
Copy after login


source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template