A: 

Can you increase the length of the sessions so they don't expire when the user closes thier browser? Set a session variable on the first time the image is loaded by the user. This way it doesn't matter if the image was requested multiple times. You only update the db when the variable isn't set.

Byron Whitlock
My problem is not reducing the number of db updates, I want to avoid the user waiting for the image to load (because of the inevitable delay of the request) from the second view of the newsletter. Thanks for the answer anyway.
iBobo
+1  A: 

From session_destroy:

In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.

Does this code work?

setcookie("PHPSESSID", 'foo', time()-3600);  /* expired 1 hour ago */

Another solution would be to serve the image through a PHP file, so whenever it gets requested, you can update your database and set a flag to your subscriber table that the newsletter was opened. Much cleaner solution IMHO. You would embed the image with code like this:

<img src="http://www.example.com/tracker.php?idhash=1234234"/&gt;

where idhash could be a combination of subscriber ID plus newsletter ID.

Gordon
I don't need to end the session, because it is started but doesn't contain anything, and I don't need to remove the cookie from the user's browser, because it has not been set yet. What I need is to avoid PHP sending the `Set-Cookie:` header at all.Thanks for the answer anyway.
iBobo
Another note, I'm already serving the image exactly like you suggest in the second part.
iBobo
Hmm, does session_cache_limiter help anything or maybe setting Caching directives via header() for the image with the serving file?
Gordon
bit of a nitpick, but `setcookie(session_name(), ...` is probably a slightly better way to reference the cookie, since session name can be overridden.
Frank Farmer
@Frank True, though the header shown in the question shows it's PHPSESSID in this case. But you are definitely right. Good suggestion.
Gordon
A: 

Are you sure the image is requested because of the session cookie, and not simply because the E-Mail client for some reason doesn't do any caching?

Pekka
Well, I really don't know if this is the case, but I have strong clues that suggest the client is actually caching: I see in my newsletter that only the image used for tracking is delayed, all of the others are instantly shown as I open the mail, and similar behavior on other newsletters. I'm even not sure the session cookie is the cause of the problem, but I think I want to try, and if this doesn't work, this might be a problem interesting to tackle on its own. Thanks for the reply.
iBobo
A: 

How about conditionally changing the session cookie name with session_name() depending on the url that's requested?

Paul Huff
Sorry, I don't get the point on doing this. Can you explain better? Thanks
iBobo
A: 

Try this:

header('Pragma:',true);
Error403.com.ar