My website has two versions, one for desktop and one for mobile. (website.com / m.website.com).
I use a PHP script to redirect my incoming mobile traffic to the mobile version of my website. For some reason, I need to know the traffic source whithin the mobile version.
To do so I use a script to set a cookie with the traffic source name, before the mobile redirection.
However I can't access the cookie with the mobile version. It seems like its not set.
$ref = $_SERVER['HTTP_REFERER'];
$refData = parse_url($ref);
if($refData['host'] == 'www.traffic_source_1.com') {
setcookie("traffic_source_1", 1, time() + (86400 * 30), "/");
}
// Redirect to mobile version
When I try to access the cookie within the mobile version I get a "not working" result.
if(isset($_COOKIE["traffic_source_1"])) {
echo "working";
} else {
echo "not working";
}
UPDATE:
Replaced
setcookie("traffic_source_1", 1, time() + (86400 * 30), "/");
To
setcookie("traffic_source_1", 1, time() + (86400 * 30), "/",".website.com");
It's working with a test cookie. However when I try to include this line into my condition it doesn't. (The condition parameters are working).