I'm stumped. 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.
Cookies time.
11
I'm stumped.
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.
The second one (below) will set the cookie and make the cookie available on the first visit. The problem with this cookie is that it disappears immediately after the page loads. So if I check the cookies right after the page loads, there's nothing there.
When I try both functions together, the result is exactly the same as if I only use the second code snippet.
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!
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.
PHP Code:
function add_cookie() {
if ($_GET['gclid']) {
$expire=time()+3888000;
setcookie("APT_cookie",$_GET['gclid'],$expire,"/",".mydomain.com");
}
}
add_action('send_headers','add_cookie');
PHP Code:
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!
- theIMgeek
- [1] reply
- ronperkins
- Sam Haenni
- [1] reply
- Western Grizzlin'
- SteveJohnson
- [1] reply
- Western Grizzlin'
- SteveJohnson
- [2] replies
- virginmind
- Western Grizzlin'
Next Topics on Trending Feed
-
11