如何读取 php 请求的 header 值?

How to read the php request header values?

所以我必须读取 PHP 中的 curl header 请求值,基本上,我必须从请求 header 中获取 CRSF 令牌和 cookie 值,然后 post post header 中的那些值来绕过登录验证。

我在 cURL 选项中尝试了 header 和 header true,但它只检索响应 header 值。

curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLINFO_HEADER_OUT, true); 

我想从请求中读取的值 header:

从您的屏幕截图(似乎来自浏览器的网络工具)来看,您似乎在谈论读取 PHP 脚本从您的浏览器请求中接收到的 header 值发送至 PHP。这与 cURL 无关 - cURL 用于将 HTTP 请求从您的 PHP 脚本发送到另一个 URL...它与 client-side 之间的交互无关] 和 PHP 通过您的网络服务器。

要从发出请求的浏览器(或其他客户端)读取进入您的 PHP 脚本的 header,您可以使用 getallheaders() 其中 returns 所有收到的 headers.

的关联数组

例如简单地列出它们:

foreach (getallheaders() as $name => $value) {
    echo "$name: $value\n";
}

文档:https://www.php.net/manual/en/function.getallheaders.php