Cookies time.
I've tried 2 functions to try to do the same thing: Set a cookie that lasts for 30 days if the visitor is from Adwords. Both work partially, but have a big flaw.
The first one (below) will set the cookie and the cookie seems like it will be there for 30 days. The problem is that my site can't read the cookie on the first visit and it's important that it does that.
function add_cookie() {
if ($_GET['gclid']) {
$expire=time()+3888000;
setcookie("APT_cookie",$_GET['gclid'],$expire,"/",".mydomain.com");
}
}
add_action('send_headers','add_cookie');
function setcookielive() {
//set a cookie as usual, but ALSO add it to $_COOKIE so the current page load has access
$_COOKIE["APT_cookie"] = $_GET['gclid'];
$expire=time()+3888000;
return setcookie("APT_cookie",$_COOKIE["APT_cookie"],$expire,"/",".mydomain.com");
}
add_action('send_headers','setcookielive');
Does anyone have any idea what's going on here? I know why the first code snippet doesn't make the cookie available on the initial page load, but I have no idea why the second code snippet creates a cookie that disappears instantly!
BTW, using this in a Wordpress plugin.
Any help appreciated!
Ask the Internet Marketing Geek <-- Happy to help with technical challenges
MiniSiteMaker.org <-- Free software to make your mini-sites fast and easy
The 2nd Amendment, 1789 - The Original Homeland Security.
Gun control means never having to say, "I missed you."
The 2nd Amendment, 1789 - The Original Homeland Security.
Gun control means never having to say, "I missed you."