I need to suppress an already set session cookie header, but I cannot find any way to do this.
Why?
I need to make an image, sent by a PHP script, cacheable by the end user; this image is used to track if a newsletter has been read by the receiver, so if the image is requested I know the newsletter has been read. I only need to know when the newsletter gets opened for the first time, the subsequent requests can be ignored. The problem is that, even if I properly set the Expire and Cache-Control headers, the image is requested every time the user opens the newsletter--only that image used for the tracking--basically because it s not cached by the user. I used this tool to understand why the URL is not cacheable, and it says because of the cookie sent.
What I want to avoid is the user seeing a delay on the load of the tracking image.
So I have a session_start()
in my website init function, that I don t want to remove, because the website is big and complicated, and making some radical change like starting the session only if needed (one of the solutions I envisioned) is not desirable. Calling session_start()
sets the Set-Cookie:
header with the PHPSESSID
cookie, and I need to remove it. Reading from the header()
page on php.net I tried setting it with an empty value like this
header( Set-Cookie: );
header( Set-Cookie: , true);
header( Set-Cookie: );
header( Set-Cookie: , true);
before and after a call to session_write_close()
, but all I obtained is that the user receives a Set-Cookie:
header, without any value, exactly as written in the header
function argument.
I must say I m still using PHP 5.2, so I cannot use the header_remove()
function I see in the manual, and lighttpd 1.4.24.
EDIT: so, it seems the tool I used to check my headers is not that good. I looked at the headers with curl --head
and saw the headers below.
HTTP/1.1 200 OK
X-Powered-By: PHP/5.2.9
Set-Cookie: PHPSESSID=qn3ms55nvst2717e7b73qqu445; path=/
Last-Modified: Sun, 29 Mar 2009 21:53:36 GMT
ETag: "cb1dffff8c10db7b0a88794b1453cab8"
Expires: Sun, 20 Dec 2009 23:28:07 GMT
Cache-Control: private, max-age=2592000
Pragma: no-cache
Content-Type: image/png
Content-Length: 1322
Date: Fri, 20 Nov 2009 23:28:07 GMT
Server: lighttpd/1.4.24
As you see it is set a Pragma: no-cache
. The tool I used said that the Pragma
header is not used, but it was wrong. I tried setting Pragma: cache
, and it made the mail client cache the image.
I made another discovery, maybe the impossibility of unsetting the Set-Cookie
header is because of lighttpd, since I cannot remove the Pragma
header using header( Pragma: )
. Looking forward to PHP 5.3. Can someone using Apache confirm that the above header
call removes the Pragma
header?
Thanks txyoji for the enlightening comment :-)
At this point it seems this question is here only to confirm lighttpd cannot remove headers by setting an header without value.