PHP获取http头响应代码没有cURL [英] PHP get http header response code without cURL

查看:164
本文介绍了PHP获取http头响应代码没有cURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个类来检测cURL是否可用,如果它使用cURL执行GET,POST,DELETE。在cURL版本中,我使用 curl_getinfo($ curl,CURLINFO_HTTP_CODE); 来获取HTTP代码。如果是cURL不可用,它使用fopen()读取文件内容。如何获取没有cURL的HTTP头代码?

I have written a class that detects if cURL is available, if it is performs GET, POST, DELETE using cURL. In the cURL version I use curl_getinfo($curl, CURLINFO_HTTP_CODE); to get the HTTP code. If is cURL is not available it uses fopen() to read the file contents. How do I get the HTTP header code without cURL?

推荐答案

每当你做一些HTTP交互时,特殊变量 $ http_response_header 将包含所有标题(包括状态行标头)。

Whenever you do some HTTP interaction, the special variable $http_response_header on the same scope will contain all headers (incl. the status line header) that are resulted from the last HTTP interaction.

请参阅这里的示例如何解析它并获取状态代码

这篇关于PHP获取http头响应代码没有cURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆