Home >php教程 >php手册 >php 获取访问页面的http状态码

php 获取访问页面的http状态码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-06 19:35:142622browse

在某种场合下,常常需要获取访问页面的http状态码,而不需要返回页面的内容。 无 ?php function GetHttpStatusCode($url){ $curl = curl_init(); curl_setopt($curl,CURLOPT_URL,$url);//获取内容url curl_setopt($curl,CURLOPT_HEADER,1);//获取http头信息 c

在某种场合下,常常需要获取访问页面的http状态码,而不需要返回页面的内容。
<?php
     function GetHttpStatusCode($url){ 
         $curl = curl_init();
         curl_setopt($curl,CURLOPT_URL,$url);//获取内容url 
         curl_setopt($curl,CURLOPT_HEADER,1);//获取http头信息 
         curl_setopt($curl,CURLOPT_NOBODY,1);//不返回html的body信息 
         curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);//返回数据流,不直接输出 
         curl_setopt($curl,CURLOPT_TIMEOUT,30); //超时时长,单位秒 
         curl_exec($curl);
         $rtn= curl_getinfo($curl,CURLINFO_HTTP_CODE);
         curl_close($curl);
         return  $rtn;
     }
     $url="http://www.putclub.com";
     echo GetHttpStatusCode($url);                                                                                                                      
 ?>
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
Previous article:PHP封装CURL扩展Next article:手机判断