如何读取php请求头的值?
所以我必须读取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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从您的屏幕截图(似乎来自浏览器的网络工具)来看,您似乎正在谈论读取 PHP 脚本从浏览器发送到 PHP 的请求中接收到的标头值。这与
cURL
无关 -cURL
用于将 HTTP 请求从 PHP 脚本发送到另一个 URL...它与客户端和 PHP 之间的交互无关你的网络服务器。要读取从发出请求的浏览器(或其他客户端)传入 PHP 脚本的标头,您可以使用 getallheaders() ,它返回所有收到的标头的关联数组。
例如,简单地列出它们:
文档: 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:
Documentation: https://www.php.net/manual/en/function.getallheaders.php