tags:

views:

34

answers:

2

Hello,

I'm trying to implement some pixel tracking where I will save certain values in a cookie to then forward users to another page. If users purchase a product after being forwarded to the online store by us the store adds an image tag in the page with our php script included. With the values set in the cookie we would like to track conversions.

I understand this tracking technique has some limitations (like if a user has cookies turned off or if they do not load images but that's the direction my client wanted to go in).

The problem I'm having is that the cookie's behaviour is extremely... random. I've been trying to track their values (with a var_dump so I don't have to wait for a page reload to view the cookie's value) but it seems the value for one field only gets refreshed every two page reloads.

    setcookie("tracking[cn]", $cn, time()+3600*24*7,'/','mydomain.com');
    setcookie("tracking[t]", $t, time()+3600*24*7,'/','mydomain.com');
    setcookie("tracking[kid]", $kid, time()+3600*24*7,'/','mydomain.com');
    redirectTo($redirect_url);

the values of cn, t are fine but for some reason kid is always wrong (having taken the value of the previous kid)

Any help would be extremely appreciated I've been at this all evening! :)

A: 

I suspect that the problem might be something in whatever code is setting $cn, $t and $kid prior to these calls.

But not sure.

thomasrutter
+1  A: 

When working with cookies you can't output information before the cookie is created.

(I didn't realize I was doing this because I wasn't receiving an error.)

Gazillion