如何读取php请求头的值?

发布于 2025-01-10 17:22:25 字数 418 浏览 0 评论 0原文

所以我必须读取PHP中的curl标头请求值,基本上,我必须从请求标头中获取CRSF令牌和cookie值,然后将这些值发布到post标头中以绕过登录身份验证。

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

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

我想从请求标头读取的值:

在此处输入图像描述

so I have to read the curl header request value in PHP, basically, I have to take the CRSF token and cookie value from the request header and then post those values in the post header to bypass the login authentication.

I tried header out and header true in cURL options but it only retrieve the response header value.

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

Values I want to read from request header:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不疑不惑不回忆 2025-01-17 17:22:25

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

要读取从发出请求的浏览器(或其他客户端)传入 PHP 脚本的标头,您可以使用 getallheaders() ,它返回所有收到的标头的关联数组。

例如,简单地列出它们:

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

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

From your screenshot (which appears to be from a browser's Network tool) it looks like you are talking about reading the header values which were received by the PHP script from the request your browser sent to PHP. That's nothing to do with cURL - cURL is for sending HTTP requests from your PHP script to another URL...it's unrelated to the interaction between the client-side and PHP via your webserver.

To read the headers which are incoming into your PHP script from the browser (or other client) making the request, you can use getallheaders() which returns an associative array of all the received headers.

e.g. to simply list them all:

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

Documentation: https://www.php.net/manual/en/function.getallheaders.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文