Home > php教程 > php手册 > PHP中使用curl取得HTTP状态码

PHP中使用curl取得HTTP状态码

WBOY
Release: 2016-06-06 20:00:40
Original
4048 people have browsed it

使用curl需要在php.ini中设置启用才行 Windows的服务器中,打开php.ini,找到: extension=php_curl.dll 去掉前面的注释既可 。 实现代码如下: $curl = curl_init(); $url=http://www.smdcn.net; curl_setopt($curl, CURLOPT_URL, $url); //设置URL curl_se

使用curl需要在php.ini中设置启用才行 > extension=php_curl.dll
去掉前面的注释既可 。

实现代码如下:

$curl = curl_init();
$url=’http://www.smdcn.net’;
curl_setopt($curl, CURLOPT_URL, $url); //设置URL
curl_setopt($curl, CURLOPT_HEADER, 1); //获取Header
curl_setopt($curl,CURLOPT_NOBODY,true); //Body就不要了吧,我们只是需要Head
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //数据存到成字符串吧,别给我直接输出到屏幕了
$data = curl_exec($curl); //开始执行啦~
echo curl_getinfo($curl,CURLINFO_HTTP_CODE); //我知道HTTPSTAT码哦~
curl_close($curl); //用完记得关掉他

Related labels:
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template