Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to suppress/remove PHP session cookie
    primarykey
    data
    text
    <p>I need to suppress an already set session cookie header, but I cannot find any way to do this.</p> <p><strike>Why?<br> 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 <a href="http://www.ircache.net/cgi-bin/cacheability.py" rel="nofollow noreferrer">tool</a> to understand why the URL is not cacheable, and it says because of the cookie sent.</p> <p>What I want to avoid is the user seeing a delay on the load of the tracking image.</strike></p> <p>So I have a <code>session_start()</code> 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 <code>session_start()</code> sets the <code>Set-Cookie:</code> header with the <code>PHPSESSID</code> cookie, and I need to remove it. Reading from the <code>header()</code> page on php.net I tried setting it with an empty value like this</p> <pre><code>header('Set-Cookie:'); header('Set-Cookie:', true); header('Set-Cookie: '); header('Set-Cookie: ', true); </code></pre> <p>before and after a call to <code>session_write_close()</code>, but all I obtained is that the user receives a <code>Set-Cookie:</code> header, without any value, exactly as written in the <code>header</code> function argument.</p> <p>I must say I'm still using PHP 5.2, so I cannot use the <code>header_remove()</code> function I see in the manual, and lighttpd 1.4.24.</p> <p><strong>EDIT:</strong> so, it seems the tool I used to check my headers is not that good. I looked at the headers with <code>curl --head</code> and saw the headers below.</p> <pre><code>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 </code></pre> <p>As you see it is set a <code>Pragma: no-cache</code>. The tool I used said that the <code>Pragma</code> header is not used, but it was wrong. I tried setting <code>Pragma: cache</code>, and it made the mail client cache the image.</p> <p>I made another discovery, maybe the impossibility of unsetting the <code>Set-Cookie</code> header is because of lighttpd, since I cannot remove the <code>Pragma</code> header using <code>header('Pragma:')</code>. Looking forward to PHP 5.3. Can someone using Apache confirm that the above <code>header</code> call removes the <code>Pragma</code> header?</p> <p>Thanks txyoji for the enlightening comment :-)</p> <p>At this point it seems this question is here only to confirm lighttpd cannot remove headers by setting an header without value.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload