php翻开其他网站猎取状况码?
php猎取http状况码程序代码
常常须要推断文件是不是能够接见,能够经由过程http状况码鉴别,200为一般接见,404为找不到该页面,代码以下
<?php // 设置url $url = 'http://www.111cn.net'; function get_http_status_code($url) { if(empty($url)) return false; $url = parse_url($url); $host = isset($url['host']) ? $url['host'] : ''; $port = isset($url['port']) ? $url['port'] : '80'; $path = isset($url['path']) ? $url['path'] : ''; $query = isset($url['query']) ? $url['query'] : ''; $request = "HEAD $path?$query HTTP/1.1rn" ."Host: $hostrn" ."Connection: closern" ."rn"; $address = gethostbyname($host); $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); socket_connect($socket, $address, $port); socket_write($socket, $request, strlen($request)); $response = split(' ', socket_read($socket, 1024)); socket_close($socket); return trim($response[1]); } echo get_http_status_code($url);
更多PHP相干学问,请接见ki4网!
以上就是php翻开其他网站猎取状况码的细致内容,更多请关注ki4网别的相干文章!