如何从curl句柄中删除以前设置的请求标头referer字段?

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.

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

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.