Question

I have the following options that I am trying to set for my cURL object:

$options = array(
  CURLOPT_URL => $targetUrl,
  CURLOPT_HEADER => false,
  CURLOPT_HTTPHEADER => array(
    'Content-Type: ' . $_SERVER['CONTENT_TYPE'],
    'Referer: ' . $_SERVER['HTTP_REFERER']
  ),
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTPAUTH => CURLAUTH_ANY,
  CURLOPT_USERPWD => "$username:$password"
);

And I get the following errors:

Notice: Undefined index: CONTENT_TYPE

Notice: Undefined index: HTTP_REFERER

Am I specifying the wrong name for those options, or are they just not being provided in the header?

Was it helpful?

Solution

The error is related to $_SERVER['CONTENT_TYPE'] and $_SERVER['HTTP_REFERER']. About Content-type you can find a explanation here: http://www.php.net/manual/en/reserved.variables.server.php#110763

And there are a few words also about HTTP_REFERER. The main point is:

The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top