admin管理员组文章数量:1401795
How to get Referrer value from cURL URL? I am trying something like this but not working.
$curldomain = "/";
$ch = curl_init($curldomain);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
$referrerValue = curl_getinfo($ch, CURLINFO_REFERER);
How to get Referrer value from cURL URL? I am trying something like this but not working.
$curldomain = "https://www.example/";
$ch = curl_init($curldomain);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
$referrerValue = curl_getinfo($ch, CURLINFO_REFERER);
Share
Improve this question
asked Mar 22 at 12:06
JK SandhiyaJK Sandhiya
1833 silver badges13 bronze badges
2
- 1 I’m not clear on what you are trying to do. The referrer header is a request header, not a response header, so you would set it and send to the server, it isn’t going to send one back to you. – Chris Haas Commented Mar 23 at 3:08
- @ChrisHaas check curl.se/libcurl/c/CURLOPT_AUTOREFERER.html (or just skim my answer) – hanshenrik Commented Mar 23 at 21:03
1 Answer
Reset to default 1Your extraction code is correct,
$referrerValue = curl_getinfo($ch, CURLINFO_REFERER);
is the correct way to fetch the last referer header sent by curl.
Curl does not track referer automatically, it is opt-in, you have to run
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
to opt-in to referer-tracking, and even then, there will only be a referer if your curl code actually set CURLOPT_FOLLOWLOCATION and follows a redirect, or you manually inject a referer with CURLOPT_REFERER.
本文标签: phpHow to get Referrer value using CURLINFO or cURLStack Overflow
版权声明:本文标题:php - How to get Referrer value using CURLINFO or cURL - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744315903a2600261.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论