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
Add a comment  | 

1 Answer 1

Reset to default 1

Your 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