2

First I initialize curl handle:

$ch = curl_init();

Next I set the url and referer headers:

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_REFERER,$referer);

And finally execute statement:

curl_exec($ch);

Now I can use another url without closing and reopening the handle, so:

curl_setopt($ch,CURLOPT_URL,$another_url);

And here headache begins, because I do not know how to disable referer header that would be send do server, of course I've tried to put false and null into CURLOPT_REFERER but it causes the referer field to be empty, that is a Referer: is still send to the server but with no value (is this even correct with http specs?).

Is there any option to remove header altogether without closing and reinstantiating curl handle ?

I'd like to avoid it because curl keeps a connection open for some time, if I would constantly close the handle while downloading from the same host it could take more time.

rsk82
  • 28,217
  • 50
  • 150
  • 240
  • Do you have to remove the header entirely? Coudld you not just set it to be the same as the url you're requesting, or the url from the previous request? – Marc B Nov 14 '11 at 19:37
  • Yes, I would like to. There could be servers that are very strict what should be in the referer. Until now I haven't encountered any, but I ask in advance. The question is really that if such behavior is correct with regard to http specification ? – rsk82 Nov 14 '11 at 19:46
  • If a bug has been filled for it, could you show me link ? – rsk82 Nov 14 '11 at 20:42
  • Some good info @ http://stackoverflow.com/questions/3787002/reusing-the-same-curl-handle-big-performance-increase – Mike Purcell Nov 14 '11 at 21:11

2 Answers2

7

You can remove completely the referer field, or any other field normally handled by curl, by passing it without anything after ":" to CURLOPT_HTTPHEADER:

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Referer:"));

And it won't appear at all in the header.

http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTHTTPHEADER

alexisdm
  • 29,448
  • 6
  • 64
  • 99
1

The Referer header should be either the full URI or a URI relative to one requested:

http://www.w3.org/Protocols/HTTP/HTRQ_Headers.html#z14

It seems like a blank Referer header meets the spec, so you could just:

curl_setopt($ch,CURLOPT_REFERER,'');

The header will still appear, but it will be blank.

Derek Kurth
  • 1,771
  • 1
  • 19
  • 19