General Question

gagara's avatar

How to make cookie in php track both in and for some web-site?

Asked by gagara (102points) May 11th, 2010

I am making website in php where I track users via cookies. For brevity reasons users are normally directed to (not the actual site, just example), but I cannot exclude users navigating also from I am having trouble creating cookies that can be tracked both from and in PHP, as PHP creates cookie in either domain, and it is not visible in the other domain. What should I do?

Observing members: 0 Composing members: 0

4 Answers

MrItty's avatar

Set the domain argument to just ’’, including the leading period, rather than accepting the default (which will be whatever the current domain is) shows the function accepts domain as the 5th argument. You have to set it explicitly.

bool setcookie ( string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] )

So you might have something like:

setcookie(‘my_cookie’, 123, 0, ””, ’’);

gagara's avatar

Thanks, that helps. Although I tried it before and it didn’t seem to work, but maybe I did something wrong at that time.

simplicity's avatar

Create a 301 redirect that redirects anyone from the www version to the non www version. Search engine friendly and makes sure everyone is in the same location.

Answer this question




to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
Knowledge Networking @ Fluther